Last active
March 11, 2019 22:30
-
-
Save camille-hdl/c5e6c7e2f8f9d6aa76ebafbc3ce2d239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import babel from "rollup-plugin-babel"; | |
import commonjs from "rollup-plugin-commonjs"; | |
import nodeResolve from "rollup-plugin-node-resolve"; | |
import { terser } from "rollup-plugin-terser"; | |
import replace from "rollup-plugin-replace"; | |
import builtins from "rollup-plugin-node-builtins"; | |
import globals from "rollup-plugin-node-globals"; | |
import clear from "rollup-plugin-clear"; | |
const outputDir = "./public/js/"; | |
const getPluginsConfig = (prod, mini) => { | |
const sortie = [ | |
clear({ | |
targets: [`${outputDir}esm`, `${outputDir}system`], | |
watch: true, | |
}), | |
nodeResolve({ | |
jsnext: true, | |
browser: true, | |
preferBuiltins: false, | |
}), | |
replace({ | |
"process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development"), | |
}), | |
commonjs({ | |
include: "node_modules/**", | |
namedExports: { | |
"./node_modules/react/index.js": [ | |
"cloneElement", | |
"createElement", | |
"PropTypes", | |
"Children", | |
"Component", | |
"createFactory", | |
"PureComponent", | |
"lazy", | |
"Suspense", | |
"useState", | |
"useEffect", | |
], | |
"./node_modules/react-dom/index.js": ["findDOMNode"], | |
"./node_modules/babel-runtime/node_modules/core-js/library/modules/es6.object.to-string.js": [ | |
"default", | |
], | |
"./node_modules/process/browser.js": ["nextTick"], | |
"./node_modules/events/events.js": ["EventEmitter"], | |
"./node_modules/react-is/index.js": ["isValidElementType"], | |
}, | |
}), | |
babel({ | |
exclude: "node_modules/**", | |
}), | |
globals(), | |
builtins(), | |
]; | |
if (mini) { | |
sortie.push( | |
terser({ | |
compress: { | |
unused: false, | |
collapse_vars: false, | |
}, | |
output: { | |
comments: !prod, | |
}, | |
sourcemap: true, | |
}) | |
); | |
} | |
return sortie; | |
}; | |
export default CLIArgs => { | |
const prod = !!CLIArgs.prod; | |
const mini = !!CLIArgs.mini; | |
const bundle = { | |
input: ["./src/index.jsx"], | |
output: [ | |
{ | |
dir: `${outputDir}system/`, | |
format: "system" | |
}, | |
{ | |
dir: `${outputDir}esm/`, | |
format: "esm" | |
}, | |
], | |
watch: { | |
include: ["./src/**"], | |
}, | |
}; | |
bundle.plugins = getPluginsConfig(prod, mini); | |
return bundle; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment