Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add history package and createMemoryHistory implementation #8702

Merged
merged 8 commits into from
Mar 10, 2022
Prev Previous commit
Next Next commit
chore: add rollup buld for history
  • Loading branch information
brophdawg11 committed Mar 4, 2022
commit 5d968c94820b4e070a0d3f518fb9932b20a86734
167 changes: 167 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,172 @@ function getVersion(sourceDir) {
return require(`./${sourceDir}/package.json`).version;
}

function history() {
const SOURCE_DIR = "packages/history";
const OUTPUT_DIR = "build/node_modules/history";
const version = getVersion(SOURCE_DIR);

// JS modules for bundlers
const modules = [
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/index.js`,
format: "esm",
sourcemap: !PRETTY,
banner: createBanner("history", version),
},
plugins: [
babel({
exclude: /node_modules/,
presets: [
["@babel/preset-env", { loose: true }],
"@babel/preset-typescript",
],
plugins: ["babel-plugin-dev-expression"],
extensions: [".ts"],
}),
copy({
targets: [
{ src: `${SOURCE_DIR}/package.json`, dest: OUTPUT_DIR },
{ src: `${SOURCE_DIR}/README.md`, dest: OUTPUT_DIR },
{ src: "LICENSE.md", dest: OUTPUT_DIR },
],
verbose: true,
}),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
];

// JS modules for <script type=module>
const webModules = [
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/history.development.js`,
format: "esm",
sourcemap: !PRETTY,
banner: createBanner("history", version),
},
plugins: [
babel({
exclude: /node_modules/,
presets: ["@babel/preset-modules", "@babel/preset-typescript"],
plugins: ["babel-plugin-dev-expression"],
extensions: [".ts"],
}),
replace({
preventAssignment: true,
values: { "process.env.NODE_ENV": JSON.stringify("development") },
}),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/history.production.min.js`,
format: "esm",
sourcemap: !PRETTY,
banner: createBanner("history", version),
},
plugins: [
babel({
exclude: /node_modules/,
presets: [
[
"@babel/preset-modules",
{
// Don't spoof `.name` for Arrow Functions, which breaks when minified anyway.
loose: true,
},
],
"@babel/preset-typescript",
],
plugins: ["babel-plugin-dev-expression"],
extensions: [".ts"],
}),
replace({
preventAssignment: true,
values: { "process.env.NODE_ENV": JSON.stringify("production") },
}),
// compiler(),
terser({ ecma: 8, safari10: true }),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
];

// UMD modules for <script> tags and CommonJS (node)
const globals = [
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/umd/history.development.js`,
format: "umd",
sourcemap: !PRETTY,
banner: createBanner("history", version),
name: "HistoryLibrary",
},
plugins: [
babel({
exclude: /node_modules/,
presets: [
["@babel/preset-env", { loose: true }],
"@babel/preset-typescript",
],
plugins: ["babel-plugin-dev-expression"],
extensions: [".ts"],
}),
replace({
preventAssignment: true,
values: { "process.env.NODE_ENV": JSON.stringify("development") },
}),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/umd/history.production.min.js`,
format: "umd",
sourcemap: !PRETTY,
banner: createBanner("history", version),
name: "HistoryLibrary",
},
plugins: [
babel({
exclude: /node_modules/,
presets: [
["@babel/preset-env", { loose: true }],
"@babel/preset-typescript",
],
plugins: ["babel-plugin-dev-expression"],
extensions: [".ts"],
}),
replace({
preventAssignment: true,
values: { "process.env.NODE_ENV": JSON.stringify("production") },
}),
// compiler(),
terser(),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
];

// Node entry points
const node = [
{
input: `${SOURCE_DIR}/node-main.js`,
output: {
file: `${OUTPUT_DIR}/main.js`,
format: "cjs",
banner: createBanner("history", version),
},
plugins: [].concat(PRETTY ? prettier({ parser: "babel" }) : []),
},
];

return [...modules, ...webModules, ...globals, ...node];
}

function reactRouter() {
const SOURCE_DIR = "packages/react-router";
const OUTPUT_DIR = "build/node_modules/react-router";
Expand Down Expand Up @@ -531,6 +697,7 @@ function reactRouterNative() {

export default function rollup(options) {
let builds = [
...history(options),
...reactRouter(options),
...reactRouterDom(options),
...reactRouterNative(options),
Expand Down