Skip to content

Commit

Permalink
Use CommonJS + fewer shared variables in Rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Feb 21, 2019
1 parent e726e99 commit 130f7ec
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 70 deletions.
46 changes: 20 additions & 26 deletions packages/react-router-config/rollup.config.js
@@ -1,33 +1,30 @@
import babel from "rollup-plugin-babel";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
import nodeResolve from "rollup-plugin-node-resolve";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
import { uglify } from "rollup-plugin-uglify";
const babel = require("rollup-plugin-babel");
const replace = require("rollup-plugin-replace");
const commonjs = require("rollup-plugin-commonjs");
const nodeResolve = require("rollup-plugin-node-resolve");
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
const { uglify } = require("rollup-plugin-uglify");

import pkg from "./package.json";
const pkg = require("./package.json");

const input = "modules/index.js";
const globalName = "ReactRouterConfig";

function external(id) {
function isBareModuleId(id) {
return !id.startsWith(".") && !id.startsWith("/");
}

const cjs = [
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
]
},
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
Expand All @@ -38,9 +35,9 @@ const cjs = [

const esm = [
{
input,
input: "modules/index.js",
output: { file: `esm/${pkg.name}.js`, format: "esm" },
external,
external: isBareModuleId,
plugins: [
babel({
exclude: /node_modules/,
Expand All @@ -52,18 +49,15 @@ const esm = [
}
];

const globals = {
react: "React",
"react-router": "ReactRouter"
};
const globals = { react: "React", "react-router": "ReactRouter" };

const umd = [
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.js`,
format: "umd",
name: globalName,
name: "ReactRouterConfig",
globals
},
external: Object.keys(globals),
Expand All @@ -80,11 +74,11 @@ const umd = [
]
},
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.min.js`,
format: "umd",
name: globalName,
name: "ReactRouterConfig",
globals
},
external: Object.keys(globals),
Expand Down Expand Up @@ -118,4 +112,4 @@ switch (process.env.BUILD_ENV) {
config = cjs.concat(esm).concat(umd);
}

export default config;
module.exports = config;
41 changes: 19 additions & 22 deletions packages/react-router-dom/rollup.config.js
@@ -1,33 +1,30 @@
import babel from "rollup-plugin-babel";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
import nodeResolve from "rollup-plugin-node-resolve";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
import { uglify } from "rollup-plugin-uglify";
const babel = require("rollup-plugin-babel");
const replace = require("rollup-plugin-replace");
const commonjs = require("rollup-plugin-commonjs");
const nodeResolve = require("rollup-plugin-node-resolve");
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
const { uglify } = require("rollup-plugin-uglify");

import pkg from "./package.json";
const pkg = require("./package.json");

const input = "modules/index.js";
const globalName = "ReactRouterDOM";

function external(id) {
function isBareModuleId(id) {
return !id.startsWith(".") && !id.startsWith("/");
}

const cjs = [
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
]
},
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
Expand All @@ -38,9 +35,9 @@ const cjs = [

const esm = [
{
input,
input: "modules/index.js",
output: { file: `esm/${pkg.name}.js`, format: "esm" },
external,
external: isBareModuleId,
plugins: [
babel({
exclude: /node_modules/,
Expand All @@ -56,11 +53,11 @@ const globals = { react: "React" };

const umd = [
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.js`,
format: "umd",
name: globalName,
name: "ReactRouterDOM",
globals
},
external: Object.keys(globals),
Expand All @@ -84,11 +81,11 @@ const umd = [
]
},
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.min.js`,
format: "umd",
name: globalName,
name: "ReactRouterDOM",
globals
},
external: Object.keys(globals),
Expand Down Expand Up @@ -129,4 +126,4 @@ switch (process.env.BUILD_ENV) {
config = cjs.concat(esm).concat(umd);
}

export default config;
module.exports = config;
41 changes: 19 additions & 22 deletions packages/react-router/rollup.config.js
@@ -1,33 +1,30 @@
import babel from "rollup-plugin-babel";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
import nodeResolve from "rollup-plugin-node-resolve";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
import { uglify } from "rollup-plugin-uglify";
const babel = require("rollup-plugin-babel");
const replace = require("rollup-plugin-replace");
const commonjs = require("rollup-plugin-commonjs");
const nodeResolve = require("rollup-plugin-node-resolve");
const { sizeSnapshot } = require("rollup-plugin-size-snapshot");
const { uglify } = require("rollup-plugin-uglify");

import pkg from "./package.json";
const pkg = require("./package.json");

const input = "modules/index.js";
const globalName = "ReactRouter";

function external(id) {
function isBareModuleId(id) {
return !id.startsWith(".") && !id.startsWith("/");
}

const cjs = [
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("development") })
]
},
{
input,
input: "modules/index.js",
output: { file: `cjs/${pkg.name}.min.js`, format: "cjs" },
external,
external: isBareModuleId,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
Expand All @@ -38,9 +35,9 @@ const cjs = [

const esm = [
{
input,
input: "modules/index.js",
output: { file: `esm/${pkg.name}.js`, format: "esm" },
external,
external: isBareModuleId,
plugins: [
babel({
exclude: /node_modules/,
Expand All @@ -56,11 +53,11 @@ const globals = { react: "React" };

const umd = [
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.js`,
format: "umd",
name: globalName,
name: "ReactRouter",
globals
},
external: Object.keys(globals),
Expand All @@ -82,11 +79,11 @@ const umd = [
]
},
{
input,
input: "modules/index.js",
output: {
file: `umd/${pkg.name}.min.js`,
format: "umd",
name: globalName,
name: "ReactRouter",
globals
},
external: Object.keys(globals),
Expand Down Expand Up @@ -125,4 +122,4 @@ switch (process.env.BUILD_ENV) {
config = cjs.concat(esm).concat(umd);
}

export default config;
module.exports = config;

0 comments on commit 130f7ec

Please sign in to comment.