-
Notifications
You must be signed in to change notification settings - Fork 7
/
rollup.config.js
77 lines (67 loc) · 1.99 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import babel from "rollup-plugin-babel";
import nodeResolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import lernaGetPackages from "lerna-get-packages";
import path from "path";
const { LERNA_PACKAGE_NAME, LERNA_ROOT_PATH } = process.env;
const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE = path.join(PACKAGE_ROOT_PATH, "src/index.js");
const OUTPUT_DIR = path.join(PACKAGE_ROOT_PATH, "dist");
const PKG_JSON = require(path.join(PACKAGE_ROOT_PATH, "package.json"));
const IS_BROWSER_BUNDLE = !!PKG_JSON.browser;
const ALL_MODULES = lernaGetPackages(LERNA_ROOT_PATH).map(
({ package: { name } }) => name
);
console.log("ALL_MODULES", ALL_MODULES)
const LOCAL_GLOBALS = {
'react': 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
'rimble-ui': 'RimbleUi',
'bowser': 'Bowser',
'@rimble/utils': 'RimbleUtils'
};
const LOCAL_EXTERNALS = [
'react',
'react-dom',
'prop-types',
'rimble-ui',
'@rimble/utils',
'bowser'
];
const mirror = array =>
array.reduce((acc, val) => ({ ...acc, [val]: val }), {});
const formats = IS_BROWSER_BUNDLE ? ["umd"] : ["es", "cjs"];
export default formats.map(format => ({
plugins: [
nodeResolve({
"jsnext:main": true,
"browser:main": true
}),
commonjs({
include: /node_modules/,
namedExports: {
"react-js": ["isValidElementType"],
"rimble-utils": ["RimbleUtils"]
}
}),
babel({
exclude: ["node_modules/**"],
presets: [['@babel/preset-env', {'modules': false}],'@babel/react'],
plugins: [['@babel/plugin-proposal-class-properties', { 'loose': true }]]
}),
],
input: INPUT_FILE,
external: IS_BROWSER_BUNDLE ? LOCAL_EXTERNALS : ALL_MODULES,
output: {
file: path.join(OUTPUT_DIR, `index.${format}.js`),
format,
sourcemap: true,
name: LERNA_PACKAGE_NAME,
globals: IS_BROWSER_BUNDLE ? mirror(ALL_MODULES) : LOCAL_GLOBALS,
amd: {
id: LERNA_PACKAGE_NAME
},
globals: LOCAL_GLOBALS
},
}));