Skip to content

Commit 9cf02f3

Browse files
authored
fix: add router UMD build for unpkg (remix-run#9446)
1 parent be0c9d3 commit 9cf02f3

File tree

6 files changed

+38
-33
lines changed

6 files changed

+38
-33
lines changed

.changeset/weak-lizards-occur.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Add UMD build for @remix-run/router

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = function rollup() {
8686
banner: createBanner("React Router DOM v5 Compat", version),
8787
globals: {
8888
history: "HistoryLibrary",
89-
"@remix-run/router": "Router",
89+
"@remix-run/router": "RemixRouter",
9090
react: "React",
9191
"react-router": "ReactRouter",
9292
"react-router-dom": "ReactRouterDOM",
@@ -128,7 +128,7 @@ module.exports = function rollup() {
128128
banner: createBanner("React Router DOM v5 Compat", version),
129129
globals: {
130130
history: "HistoryLibrary",
131-
"@remix-run/router": "Router",
131+
"@remix-run/router": "RemixRouter",
132132
react: "React",
133133
"react-router": "ReactRouter",
134134
"react-router-dom": "ReactRouterDOM",

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

+7-17
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ module.exports = function rollup() {
2626
sourcemap: !PRETTY,
2727
banner: createBanner("React Router DOM", version),
2828
},
29-
external: [
30-
"history",
31-
"react",
32-
"react-dom",
33-
"react-router",
34-
"@remix-run/router",
35-
],
29+
external: ["react", "react-dom", "react-router", "@remix-run/router"],
3630
plugins: [
3731
extensions({ extensions: [".ts", ".tsx"] }),
3832
babel({
@@ -73,7 +67,7 @@ module.exports = function rollup() {
7367
sourcemap: !PRETTY,
7468
banner: createBanner("React Router DOM", version),
7569
},
76-
external: ["history", "react", "react-router", "@remix-run/router"],
70+
external: ["react", "react-router", "@remix-run/router"],
7771
plugins: [
7872
extensions({ extensions: [".ts", ".tsx"] }),
7973
babel({
@@ -101,7 +95,7 @@ module.exports = function rollup() {
10195
sourcemap: !PRETTY,
10296
banner: createBanner("React Router DOM", version),
10397
},
104-
external: ["history", "react", "react-router", "@remix-run/router"],
98+
external: ["react", "react-router", "@remix-run/router"],
10599
plugins: [
106100
extensions({ extensions: [".ts", ".tsx"] }),
107101
babel({
@@ -147,14 +141,13 @@ module.exports = function rollup() {
147141
sourcemap: !PRETTY,
148142
banner: createBanner("React Router DOM", version),
149143
globals: {
150-
history: "HistoryLibrary",
151-
"@remix-run/router": "Router",
144+
"@remix-run/router": "RemixRouter",
152145
react: "React",
153146
"react-router": "ReactRouter",
154147
},
155148
name: "ReactRouterDOM",
156149
},
157-
external: ["history", "react", "react-router", "@remix-run/router"],
150+
external: ["react", "react-router", "@remix-run/router"],
158151
plugins: [
159152
extensions({ extensions: [".ts", ".tsx"] }),
160153
babel({
@@ -182,14 +175,13 @@ module.exports = function rollup() {
182175
sourcemap: !PRETTY,
183176
banner: createBanner("React Router DOM", version),
184177
globals: {
185-
history: "HistoryLibrary",
186-
"@remix-run/router": "Router",
178+
"@remix-run/router": "RemixRouter",
187179
react: "React",
188180
"react-router": "ReactRouter",
189181
},
190182
name: "ReactRouterDOM",
191183
},
192-
external: ["history", "react", "react-router", "@remix-run/router"],
184+
external: ["react", "react-router", "@remix-run/router"],
193185
plugins: [
194186
extensions({ extensions: [".ts", ".tsx"] }),
195187
babel({
@@ -240,7 +232,6 @@ module.exports = function rollup() {
240232
],
241233
external: [
242234
"url",
243-
"history",
244235
"react",
245236
"react-dom/server",
246237
"react-router-dom",
@@ -284,7 +275,6 @@ module.exports = function rollup() {
284275
],
285276
external: [
286277
"url",
287-
"history",
288278
"react",
289279
"react-dom/server",
290280
"react-router-dom",

packages/react-router/rollup.config.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function rollup() {
2626
sourcemap: !PRETTY,
2727
banner: createBanner("React Router", version),
2828
},
29-
external: ["history", "@remix-run/router", "react"],
29+
external: ["@remix-run/router", "react"],
3030
plugins: [
3131
extensions({ extensions: [".tsx", ".ts"] }),
3232
babel({
@@ -60,7 +60,7 @@ module.exports = function rollup() {
6060
sourcemap: !PRETTY,
6161
banner: createBanner("React Router", version),
6262
},
63-
external: ["history", "@remix-run/router", "react"],
63+
external: ["@remix-run/router", "react"],
6464
plugins: [
6565
extensions({ extensions: [".tsx", ".ts"] }),
6666
babel({
@@ -93,7 +93,7 @@ module.exports = function rollup() {
9393
sourcemap: !PRETTY,
9494
banner: createBanner("React Router", version),
9595
},
96-
external: ["history", "@remix-run/router", "react"],
96+
external: ["@remix-run/router", "react"],
9797
plugins: [
9898
extensions({ extensions: [".tsx", ".ts"] }),
9999
babel({
@@ -139,13 +139,12 @@ module.exports = function rollup() {
139139
sourcemap: !PRETTY,
140140
banner: createBanner("React Router", version),
141141
globals: {
142-
history: "HistoryLibrary",
143-
"@remix-run/router": "Router",
142+
"@remix-run/router": "RemixRouter",
144143
react: "React",
145144
},
146145
name: "ReactRouter",
147146
},
148-
external: ["history", "@remix-run/router", "react"],
147+
external: ["@remix-run/router", "react"],
149148
plugins: [
150149
extensions({ extensions: [".tsx", ".ts"] }),
151150
babel({
@@ -173,13 +172,12 @@ module.exports = function rollup() {
173172
sourcemap: !PRETTY,
174173
banner: createBanner("React Router", version),
175174
globals: {
176-
history: "HistoryLibrary",
177-
"@remix-run/router": "Router",
175+
"@remix-run/router": "RemixRouter",
178176
react: "React",
179177
},
180178
name: "ReactRouter",
181179
},
182-
external: ["history", "@remix-run/router", "react"],
180+
external: ["@remix-run/router", "react"],
183181
plugins: [
184182
extensions({ extensions: [".tsx", ".ts"] }),
185183
babel({

packages/router/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"author": "Remix Software <[email protected]>",
1717
"sideEffects": false,
1818
"main": "./dist/router.cjs.js",
19+
"unpkg": "./dist/router.umd.min.js",
1920
"module": "./dist/router.js",
2021
"types": "./dist/index.d.ts",
2122
"files": [

packages/router/rollup.config.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
const path = require("path");
2+
23
const babel = require("@rollup/plugin-babel").default;
4+
const typescript = require("@rollup/plugin-typescript");
35
const copy = require("rollup-plugin-copy");
46
const extensions = require("rollup-plugin-extensions");
57
const prettier = require("rollup-plugin-prettier");
6-
const typescript = require("@rollup/plugin-typescript");
8+
const { terser } = require("rollup-plugin-terser");
9+
710
const {
811
createBanner,
912
getBuildDirectories,
1013
PRETTY,
1114
} = require("../../rollup.utils");
1215
const { name, version } = require("./package.json");
1316

14-
function getRollupConfig(format, filename, includeTypesAndCopy = false) {
17+
function getRollupConfig(
18+
format,
19+
filename,
20+
{ includeTypesAndCopy, minify } = {}
21+
) {
1522
const { ROOT_DIR, SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories(
1623
name,
1724
// We don't live in a folder matching our package name
@@ -25,6 +32,7 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
2532
format,
2633
sourcemap: !PRETTY,
2734
banner: createBanner("@remix-run/router", version),
35+
...(format === "umd" ? { name: "RemixRouter" } : {}),
2836
},
2937
plugins: [
3038
extensions({ extensions: [".ts"] }),
@@ -37,7 +45,7 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
3745
],
3846
extensions: [".ts"],
3947
}),
40-
...(includeTypesAndCopy
48+
...(includeTypesAndCopy === true
4149
? [
4250
typescript({
4351
tsconfig: path.join(__dirname, "tsconfig.json"),
@@ -52,14 +60,17 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
5260
}),
5361
]
5462
: []),
63+
...(minify === true ? [terser()] : []),
5564
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
5665
};
5766
}
5867

5968
module.exports = function rollup() {
6069
return [
61-
getRollupConfig("esm", "router.js", true),
62-
getRollupConfig("cjs", "router.cjs.js", false),
70+
getRollupConfig("esm", "router.js", { includeTypesAndCopy: true }),
71+
getRollupConfig("cjs", "router.cjs.js"),
72+
getRollupConfig("umd", "router.umd.js"),
73+
getRollupConfig("umd", "router.umd.min.js", { minify: true }),
6374
];
6475
};
6576

0 commit comments

Comments
 (0)