Skip to content

Commit b2c6fa0

Browse files
committedFeb 22, 2019
Throw when using 2 different builds in dev
Fixes #6361
1 parent 130f7ec commit b2c6fa0

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed
 

‎packages/react-router-dom/.size-snapshot.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
}
1515
},
1616
"umd/react-router-dom.js": {
17-
"bundled": 161325,
18-
"minified": 57478,
19-
"gzipped": 16483
17+
"bundled": 162042,
18+
"minified": 57823,
19+
"gzipped": 16684
2020
},
2121
"umd/react-router-dom.min.js": {
2222
"bundled": 97926,

‎packages/react-router/.size-snapshot.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"esm/react-router.js": {
3-
"bundled": 22391,
4-
"minified": 12617,
5-
"gzipped": 3438,
3+
"bundled": 23114,
4+
"minified": 13111,
5+
"gzipped": 3670,
66
"treeshaked": {
77
"rollup": {
88
"code": 2267,
@@ -14,9 +14,9 @@
1414
}
1515
},
1616
"umd/react-router.js": {
17-
"bundled": 101474,
18-
"minified": 35902,
19-
"gzipped": 11344
17+
"bundled": 102208,
18+
"minified": 36247,
19+
"gzipped": 11540
2020
},
2121
"umd/react-router.min.js": {
2222
"bundled": 63839,

‎packages/react-router/modules/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
if (__DEV__) {
2+
const global = (1, eval)("this");
3+
const key = "__react_router_build__";
4+
const buildNames = { cjs: "CommonJS", esm: "ES modules", umd: "UMD" };
5+
6+
if (global[key] && global[key] !== process.env.BUILD_FORMAT) {
7+
const initialBuildName = buildNames[global[key]];
8+
const secondaryBuildName = buildNames[process.env.BUILD_FORMAT];
9+
10+
// TODO: Add link to article that explains in detail how to avoid
11+
// loading 2 different builds.
12+
throw new Error(
13+
`You are loading the ${secondaryBuildName} build of React Router ` +
14+
`on a page that is already running the ${initialBuildName} ` +
15+
`build, so things won't work right.`
16+
);
17+
}
18+
19+
global[key] = process.env.BUILD_FORMAT;
20+
}
21+
122
export { default as MemoryRouter } from "./MemoryRouter";
223
export { default as Prompt } from "./Prompt";
324
export { default as Redirect } from "./Redirect";

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const cjs = [
1818
external: isBareModuleId,
1919
plugins: [
2020
babel({ exclude: /node_modules/ }),
21-
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
21+
replace({
22+
"process.env.NODE_ENV": JSON.stringify("development"),
23+
"process.env.BUILD_FORMAT": JSON.stringify("cjs")
24+
})
2225
]
2326
},
2427
{
@@ -27,7 +30,10 @@ const cjs = [
2730
external: isBareModuleId,
2831
plugins: [
2932
babel({ exclude: /node_modules/ }),
30-
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
33+
replace({
34+
"process.env.NODE_ENV": JSON.stringify("production"),
35+
"process.env.BUILD_FORMAT": JSON.stringify("cjs")
36+
}),
3137
uglify()
3238
]
3339
}
@@ -44,6 +50,7 @@ const esm = [
4450
runtimeHelpers: true,
4551
plugins: [["@babel/transform-runtime", { useESModules: true }]]
4652
}),
53+
replace({ "process.env.BUILD_FORMAT": JSON.stringify("esm") }),
4754
sizeSnapshot()
4855
]
4956
}
@@ -74,7 +81,10 @@ const umd = [
7481
"node_modules/react-is/index.js": ["isValidElementType"]
7582
}
7683
}),
77-
replace({ "process.env.NODE_ENV": JSON.stringify("development") }),
84+
replace({
85+
"process.env.NODE_ENV": JSON.stringify("development"),
86+
"process.env.BUILD_FORMAT": JSON.stringify("umd")
87+
}),
7888
sizeSnapshot()
7989
]
8090
},
@@ -100,7 +110,10 @@ const umd = [
100110
"node_modules/react-is/index.js": ["isValidElementType"]
101111
}
102112
}),
103-
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
113+
replace({
114+
"process.env.NODE_ENV": JSON.stringify("production"),
115+
"process.env.BUILD_FORMAT": JSON.stringify("umd")
116+
}),
104117
sizeSnapshot(),
105118
uglify()
106119
]

0 commit comments

Comments
 (0)
Please sign in to comment.