Skip to content

Commit

Permalink
fix: add router UMD build for unpkg (#9446)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Oct 17, 2022
1 parent be0c9d3 commit 9cf02f3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-lizards-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Add UMD build for @remix-run/router
4 changes: 2 additions & 2 deletions packages/react-router-dom-v5-compat/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = function rollup() {
banner: createBanner("React Router DOM v5 Compat", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
"react-router": "ReactRouter",
"react-router-dom": "ReactRouterDOM",
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = function rollup() {
banner: createBanner("React Router DOM v5 Compat", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
"react-router": "ReactRouter",
"react-router-dom": "ReactRouterDOM",
Expand Down
24 changes: 7 additions & 17 deletions packages/react-router-dom/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
},
external: [
"history",
"react",
"react-dom",
"react-router",
"@remix-run/router",
],
external: ["react", "react-dom", "react-router", "@remix-run/router"],
plugins: [
extensions({ extensions: [".ts", ".tsx"] }),
babel({
Expand Down Expand Up @@ -73,7 +67,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
},
external: ["history", "react", "react-router", "@remix-run/router"],
external: ["react", "react-router", "@remix-run/router"],
plugins: [
extensions({ extensions: [".ts", ".tsx"] }),
babel({
Expand Down Expand Up @@ -101,7 +95,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
},
external: ["history", "react", "react-router", "@remix-run/router"],
external: ["react", "react-router", "@remix-run/router"],
plugins: [
extensions({ extensions: [".ts", ".tsx"] }),
babel({
Expand Down Expand Up @@ -147,14 +141,13 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
"react-router": "ReactRouter",
},
name: "ReactRouterDOM",
},
external: ["history", "react", "react-router", "@remix-run/router"],
external: ["react", "react-router", "@remix-run/router"],
plugins: [
extensions({ extensions: [".ts", ".tsx"] }),
babel({
Expand Down Expand Up @@ -182,14 +175,13 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
"react-router": "ReactRouter",
},
name: "ReactRouterDOM",
},
external: ["history", "react", "react-router", "@remix-run/router"],
external: ["react", "react-router", "@remix-run/router"],
plugins: [
extensions({ extensions: [".ts", ".tsx"] }),
babel({
Expand Down Expand Up @@ -240,7 +232,6 @@ module.exports = function rollup() {
],
external: [
"url",
"history",
"react",
"react-dom/server",
"react-router-dom",
Expand Down Expand Up @@ -284,7 +275,6 @@ module.exports = function rollup() {
],
external: [
"url",
"history",
"react",
"react-dom/server",
"react-router-dom",
Expand Down
16 changes: 7 additions & 9 deletions packages/react-router/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
},
external: ["history", "@remix-run/router", "react"],
external: ["@remix-run/router", "react"],
plugins: [
extensions({ extensions: [".tsx", ".ts"] }),
babel({
Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
},
external: ["history", "@remix-run/router", "react"],
external: ["@remix-run/router", "react"],
plugins: [
extensions({ extensions: [".tsx", ".ts"] }),
babel({
Expand Down Expand Up @@ -93,7 +93,7 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
},
external: ["history", "@remix-run/router", "react"],
external: ["@remix-run/router", "react"],
plugins: [
extensions({ extensions: [".tsx", ".ts"] }),
babel({
Expand Down Expand Up @@ -139,13 +139,12 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
},
name: "ReactRouter",
},
external: ["history", "@remix-run/router", "react"],
external: ["@remix-run/router", "react"],
plugins: [
extensions({ extensions: [".tsx", ".ts"] }),
babel({
Expand Down Expand Up @@ -173,13 +172,12 @@ module.exports = function rollup() {
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
globals: {
history: "HistoryLibrary",
"@remix-run/router": "Router",
"@remix-run/router": "RemixRouter",
react: "React",
},
name: "ReactRouter",
},
external: ["history", "@remix-run/router", "react"],
external: ["@remix-run/router", "react"],
plugins: [
extensions({ extensions: [".tsx", ".ts"] }),
babel({
Expand Down
1 change: 1 addition & 0 deletions packages/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"author": "Remix Software <hello@remix.run>",
"sideEffects": false,
"main": "./dist/router.cjs.js",
"unpkg": "./dist/router.umd.min.js",
"module": "./dist/router.js",
"types": "./dist/index.d.ts",
"files": [
Expand Down
21 changes: 16 additions & 5 deletions packages/router/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
const path = require("path");

const babel = require("@rollup/plugin-babel").default;
const typescript = require("@rollup/plugin-typescript");
const copy = require("rollup-plugin-copy");
const extensions = require("rollup-plugin-extensions");
const prettier = require("rollup-plugin-prettier");
const typescript = require("@rollup/plugin-typescript");
const { terser } = require("rollup-plugin-terser");

const {
createBanner,
getBuildDirectories,
PRETTY,
} = require("../../rollup.utils");
const { name, version } = require("./package.json");

function getRollupConfig(format, filename, includeTypesAndCopy = false) {
function getRollupConfig(
format,
filename,
{ includeTypesAndCopy, minify } = {}
) {
const { ROOT_DIR, SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories(
name,
// We don't live in a folder matching our package name
Expand All @@ -25,6 +32,7 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
format,
sourcemap: !PRETTY,
banner: createBanner("@remix-run/router", version),
...(format === "umd" ? { name: "RemixRouter" } : {}),
},
plugins: [
extensions({ extensions: [".ts"] }),
Expand All @@ -37,7 +45,7 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
],
extensions: [".ts"],
}),
...(includeTypesAndCopy
...(includeTypesAndCopy === true
? [
typescript({
tsconfig: path.join(__dirname, "tsconfig.json"),
Expand All @@ -52,14 +60,17 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) {
}),
]
: []),
...(minify === true ? [terser()] : []),
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
};
}

module.exports = function rollup() {
return [
getRollupConfig("esm", "router.js", true),
getRollupConfig("cjs", "router.cjs.js", false),
getRollupConfig("esm", "router.js", { includeTypesAndCopy: true }),
getRollupConfig("cjs", "router.cjs.js"),
getRollupConfig("umd", "router.umd.js"),
getRollupConfig("umd", "router.umd.min.js", { minify: true }),
];
};

Expand Down

0 comments on commit 9cf02f3

Please sign in to comment.