From 2a8b60cf3f2e8b01fbf7a536805fd155f2d059af Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Tue, 11 Oct 2022 16:29:34 -0400 Subject: [PATCH 1/4] fix: add router UMD build for unpkg --- packages/router/package.json | 1 + packages/router/rollup.config.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/router/package.json b/packages/router/package.json index a9db873260..6dbc30e704 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -16,6 +16,7 @@ "author": "Remix Software ", "sideEffects": false, "main": "./dist/router.cjs.js", + "unpkg": "./dist/router.umd.min.js", "module": "./dist/router.js", "types": "./dist/index.d.ts", "files": [ diff --git a/packages/router/rollup.config.js b/packages/router/rollup.config.js index 3ebc0fb2cb..78cf1c6858 100644 --- a/packages/router/rollup.config.js +++ b/packages/router/rollup.config.js @@ -1,9 +1,12 @@ 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, @@ -11,7 +14,11 @@ const { } = 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 @@ -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"] }), @@ -37,7 +45,7 @@ function getRollupConfig(format, filename, includeTypesAndCopy = false) { ], extensions: [".ts"], }), - ...(includeTypesAndCopy + ...(includeTypesAndCopy === true ? [ typescript({ tsconfig: path.join(__dirname, "tsconfig.json"), @@ -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 }), ]; }; From 331e90c4912acb7422bd6c3152bae2dc65dd6f91 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 12 Oct 2022 16:17:37 -0400 Subject: [PATCH 2/4] update other packages to reference RemixRouter UMD name --- packages/react-router-dom-v5-compat/rollup.config.js | 4 ++-- packages/react-router-dom/rollup.config.js | 4 ++-- packages/react-router/rollup.config.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-router-dom-v5-compat/rollup.config.js b/packages/react-router-dom-v5-compat/rollup.config.js index 1971a95083..82fed85f33 100644 --- a/packages/react-router-dom-v5-compat/rollup.config.js +++ b/packages/react-router-dom-v5-compat/rollup.config.js @@ -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", @@ -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", diff --git a/packages/react-router-dom/rollup.config.js b/packages/react-router-dom/rollup.config.js index 37df554bf5..263dac5f3c 100644 --- a/packages/react-router-dom/rollup.config.js +++ b/packages/react-router-dom/rollup.config.js @@ -148,7 +148,7 @@ module.exports = function rollup() { banner: createBanner("React Router DOM", version), globals: { history: "HistoryLibrary", - "@remix-run/router": "Router", + "@remix-run/router": "RemixRouter", react: "React", "react-router": "ReactRouter", }, @@ -183,7 +183,7 @@ module.exports = function rollup() { banner: createBanner("React Router DOM", version), globals: { history: "HistoryLibrary", - "@remix-run/router": "Router", + "@remix-run/router": "RemixRouter", react: "React", "react-router": "ReactRouter", }, diff --git a/packages/react-router/rollup.config.js b/packages/react-router/rollup.config.js index e604c850ff..f543ba14b5 100644 --- a/packages/react-router/rollup.config.js +++ b/packages/react-router/rollup.config.js @@ -140,7 +140,7 @@ module.exports = function rollup() { banner: createBanner("React Router", version), globals: { history: "HistoryLibrary", - "@remix-run/router": "Router", + "@remix-run/router": "RemixRouter", react: "React", }, name: "ReactRouter", @@ -174,7 +174,7 @@ module.exports = function rollup() { banner: createBanner("React Router", version), globals: { history: "HistoryLibrary", - "@remix-run/router": "Router", + "@remix-run/router": "RemixRouter", react: "React", }, name: "ReactRouter", From e83c100be79c1f36fc2f7655e0b48456fd74f48c Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 12 Oct 2022 16:18:02 -0400 Subject: [PATCH 3/4] Remove stale history references from rollup builds --- packages/react-router-dom/rollup.config.js | 20 +++++--------------- packages/react-router/rollup.config.js | 12 +++++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/react-router-dom/rollup.config.js b/packages/react-router-dom/rollup.config.js index 263dac5f3c..0a816d13a2 100644 --- a/packages/react-router-dom/rollup.config.js +++ b/packages/react-router-dom/rollup.config.js @@ -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({ @@ -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({ @@ -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({ @@ -147,14 +141,13 @@ module.exports = function rollup() { sourcemap: !PRETTY, banner: createBanner("React Router DOM", version), globals: { - history: "HistoryLibrary", "@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({ @@ -182,14 +175,13 @@ module.exports = function rollup() { sourcemap: !PRETTY, banner: createBanner("React Router DOM", version), globals: { - history: "HistoryLibrary", "@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({ @@ -240,7 +232,6 @@ module.exports = function rollup() { ], external: [ "url", - "history", "react", "react-dom/server", "react-router-dom", @@ -284,7 +275,6 @@ module.exports = function rollup() { ], external: [ "url", - "history", "react", "react-dom/server", "react-router-dom", diff --git a/packages/react-router/rollup.config.js b/packages/react-router/rollup.config.js index f543ba14b5..ff9d98a671 100644 --- a/packages/react-router/rollup.config.js +++ b/packages/react-router/rollup.config.js @@ -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({ @@ -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({ @@ -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({ @@ -139,13 +139,12 @@ module.exports = function rollup() { sourcemap: !PRETTY, banner: createBanner("React Router", version), globals: { - history: "HistoryLibrary", "@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({ @@ -173,13 +172,12 @@ module.exports = function rollup() { sourcemap: !PRETTY, banner: createBanner("React Router", version), globals: { - history: "HistoryLibrary", "@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({ From 227503789ceff57bf6c42fec0c74332edb30c718 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 12 Oct 2022 16:18:38 -0400 Subject: [PATCH 4/4] add changeset --- .changeset/weak-lizards-occur.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/weak-lizards-occur.md diff --git a/.changeset/weak-lizards-occur.md b/.changeset/weak-lizards-occur.md new file mode 100644 index 0000000000..1a2bfbf475 --- /dev/null +++ b/.changeset/weak-lizards-occur.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Add UMD build for @remix-run/router