Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add router UMD build for unpkg #9446

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UMD name for the build is RemixRouter for clarity - Router felt a bit vague 😄

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"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-router-dom no longer depends on history so it can be removed from external and globals

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"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for react-router, no longer depends on history

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 }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dev and prod UMD builds for @remix-run/router

];
};

Expand Down