Skip to content

Commit 130f7ec

Browse files
committed
Use CommonJS + fewer shared variables in Rollup config
1 parent e726e99 commit 130f7ec

File tree

3 files changed

+58
-70
lines changed

3 files changed

+58
-70
lines changed

packages/react-router-config/rollup.config.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import babel from "rollup-plugin-babel";
2-
import replace from "rollup-plugin-replace";
3-
import commonjs from "rollup-plugin-commonjs";
4-
import nodeResolve from "rollup-plugin-node-resolve";
5-
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
6-
import { uglify } from "rollup-plugin-uglify";
1+
const babel = require("rollup-plugin-babel");
2+
const replace = require("rollup-plugin-replace");
3+
const commonjs = require("rollup-plugin-commonjs");
4+
const nodeResolve = require("rollup-plugin-node-resolve");
5+
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
6+
const { uglify } = require("rollup-plugin-uglify");
77

8-
import pkg from "./package.json";
8+
const pkg = require("./package.json");
99

10-
const input = "modules/index.js";
11-
const globalName = "ReactRouterConfig";
12-
13-
function external(id) {
10+
function isBareModuleId(id) {
1411
return !id.startsWith(".") && !id.startsWith("/");
1512
}
1613

1714
const cjs = [
1815
{
19-
input,
16+
input: "modules/index.js",
2017
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
21-
external,
18+
external: isBareModuleId,
2219
plugins: [
2320
babel({ exclude: /node_modules/ }),
2421
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
2522
]
2623
},
2724
{
28-
input,
25+
input: "modules/index.js",
2926
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
30-
external,
27+
external: isBareModuleId,
3128
plugins: [
3229
babel({ exclude: /node_modules/ }),
3330
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
@@ -38,9 +35,9 @@ const cjs = [
3835

3936
const esm = [
4037
{
41-
input,
38+
input: "modules/index.js",
4239
output: { file: `esm/${pkg.name}.js`, format: "esm" },
43-
external,
40+
external: isBareModuleId,
4441
plugins: [
4542
babel({
4643
exclude: /node_modules/,
@@ -52,18 +49,15 @@ const esm = [
5249
}
5350
];
5451

55-
const globals = {
56-
react: "React",
57-
"react-router": "ReactRouter"
58-
};
52+
const globals = { react: "React", "react-router": "ReactRouter" };
5953

6054
const umd = [
6155
{
62-
input,
56+
input: "modules/index.js",
6357
output: {
6458
file: `umd/${pkg.name}.js`,
6559
format: "umd",
66-
name: globalName,
60+
name: "ReactRouterConfig",
6761
globals
6862
},
6963
external: Object.keys(globals),
@@ -80,11 +74,11 @@ const umd = [
8074
]
8175
},
8276
{
83-
input,
77+
input: "modules/index.js",
8478
output: {
8579
file: `umd/${pkg.name}.min.js`,
8680
format: "umd",
87-
name: globalName,
81+
name: "ReactRouterConfig",
8882
globals
8983
},
9084
external: Object.keys(globals),
@@ -118,4 +112,4 @@ switch (process.env.BUILD_ENV) {
118112
config = cjs.concat(esm).concat(umd);
119113
}
120114

121-
export default config;
115+
module.exports = config;

packages/react-router-dom/rollup.config.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import babel from "rollup-plugin-babel";
2-
import replace from "rollup-plugin-replace";
3-
import commonjs from "rollup-plugin-commonjs";
4-
import nodeResolve from "rollup-plugin-node-resolve";
5-
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
6-
import { uglify } from "rollup-plugin-uglify";
1+
const babel = require("rollup-plugin-babel");
2+
const replace = require("rollup-plugin-replace");
3+
const commonjs = require("rollup-plugin-commonjs");
4+
const nodeResolve = require("rollup-plugin-node-resolve");
5+
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
6+
const { uglify } = require("rollup-plugin-uglify");
77

8-
import pkg from "./package.json";
8+
const pkg = require("./package.json");
99

10-
const input = "modules/index.js";
11-
const globalName = "ReactRouterDOM";
12-
13-
function external(id) {
10+
function isBareModuleId(id) {
1411
return !id.startsWith(".") && !id.startsWith("/");
1512
}
1613

1714
const cjs = [
1815
{
19-
input,
16+
input: "modules/index.js",
2017
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
21-
external,
18+
external: isBareModuleId,
2219
plugins: [
2320
babel({ exclude: /node_modules/ }),
2421
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
2522
]
2623
},
2724
{
28-
input,
25+
input: "modules/index.js",
2926
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
30-
external,
27+
external: isBareModuleId,
3128
plugins: [
3229
babel({ exclude: /node_modules/ }),
3330
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
@@ -38,9 +35,9 @@ const cjs = [
3835

3936
const esm = [
4037
{
41-
input,
38+
input: "modules/index.js",
4239
output: { file: `esm/${pkg.name}.js`, format: "esm" },
43-
external,
40+
external: isBareModuleId,
4441
plugins: [
4542
babel({
4643
exclude: /node_modules/,
@@ -56,11 +53,11 @@ const globals = { react: "React" };
5653

5754
const umd = [
5855
{
59-
input,
56+
input: "modules/index.js",
6057
output: {
6158
file: `umd/${pkg.name}.js`,
6259
format: "umd",
63-
name: globalName,
60+
name: "ReactRouterDOM",
6461
globals
6562
},
6663
external: Object.keys(globals),
@@ -84,11 +81,11 @@ const umd = [
8481
]
8582
},
8683
{
87-
input,
84+
input: "modules/index.js",
8885
output: {
8986
file: `umd/${pkg.name}.min.js`,
9087
format: "umd",
91-
name: globalName,
88+
name: "ReactRouterDOM",
9289
globals
9390
},
9491
external: Object.keys(globals),
@@ -129,4 +126,4 @@ switch (process.env.BUILD_ENV) {
129126
config = cjs.concat(esm).concat(umd);
130127
}
131128

132-
export default config;
129+
module.exports = config;

packages/react-router/rollup.config.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import babel from "rollup-plugin-babel";
2-
import replace from "rollup-plugin-replace";
3-
import commonjs from "rollup-plugin-commonjs";
4-
import nodeResolve from "rollup-plugin-node-resolve";
5-
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
6-
import { uglify } from "rollup-plugin-uglify";
1+
const babel = require("rollup-plugin-babel");
2+
const replace = require("rollup-plugin-replace");
3+
const commonjs = require("rollup-plugin-commonjs");
4+
const nodeResolve = require("rollup-plugin-node-resolve");
5+
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
6+
const { uglify } = require("rollup-plugin-uglify");
77

8-
import pkg from "./package.json";
8+
const pkg = require("./package.json");
99

10-
const input = "modules/index.js";
11-
const globalName = "ReactRouter";
12-
13-
function external(id) {
10+
function isBareModuleId(id) {
1411
return !id.startsWith(".") && !id.startsWith("/");
1512
}
1613

1714
const cjs = [
1815
{
19-
input,
16+
input: "modules/index.js",
2017
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
21-
external,
18+
external: isBareModuleId,
2219
plugins: [
2320
babel({ exclude: /node_modules/ }),
2421
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
2522
]
2623
},
2724
{
28-
input,
25+
input: "modules/index.js",
2926
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
30-
external,
27+
external: isBareModuleId,
3128
plugins: [
3229
babel({ exclude: /node_modules/ }),
3330
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
@@ -38,9 +35,9 @@ const cjs = [
3835

3936
const esm = [
4037
{
41-
input,
38+
input: "modules/index.js",
4239
output: { file: `esm/${pkg.name}.js`, format: "esm" },
43-
external,
40+
external: isBareModuleId,
4441
plugins: [
4542
babel({
4643
exclude: /node_modules/,
@@ -56,11 +53,11 @@ const globals = { react: "React" };
5653

5754
const umd = [
5855
{
59-
input,
56+
input: "modules/index.js",
6057
output: {
6158
file: `umd/${pkg.name}.js`,
6259
format: "umd",
63-
name: globalName,
60+
name: "ReactRouter",
6461
globals
6562
},
6663
external: Object.keys(globals),
@@ -82,11 +79,11 @@ const umd = [
8279
]
8380
},
8481
{
85-
input,
82+
input: "modules/index.js",
8683
output: {
8784
file: `umd/${pkg.name}.min.js`,
8885
format: "umd",
89-
name: globalName,
86+
name: "ReactRouter",
9087
globals
9188
},
9289
external: Object.keys(globals),
@@ -125,4 +122,4 @@ switch (process.env.BUILD_ENV) {
125122
config = cjs.concat(esm).concat(umd);
126123
}
127124

128-
export default config;
125+
module.exports = config;

0 commit comments

Comments
 (0)