forked from ctrlplusb/easy-peasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
105 lines (99 loc) · 2.82 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* eslint-disable no-param-reassign */
const { uglify } = require('rollup-plugin-uglify');
const babel = require('rollup-plugin-babel');
const { titleCase } = require('title-case');
const produce = require('immer-peasy').default;
const replace = require('rollup-plugin-replace');
const fileSize = require('rollup-plugin-filesize');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const packageJson = require('./package.json');
process.env.BABEL_ENV = 'production';
const baseConfig = {
external: [
'debounce',
'is-plain-object',
'immer-peasy',
'memoizerific',
'react',
'redux',
'redux-thunk',
],
input: 'src/index.js',
output: {
sourcemap: true,
},
plugins: [
babel({
babelrc: false,
exclude: 'node_modules/**',
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['ie >= 11'],
},
modules: false,
loose: true,
},
],
'@babel/preset-react',
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
['@babel/plugin-proposal-class-properties', { loose: false }],
'@babel/plugin-proposal-json-strings',
['transform-react-remove-prop-types', { removeImport: true }],
],
}),
],
};
const commonUMD = config =>
produce(config, draft => {
draft.output.format = 'umd';
draft.output.globals = {
debounce: 'debounce',
'is-plain-object': 'isPlainObject',
memoizerific: 'memoizerific',
'redux-thunk': 'ReduxThunk',
'immer-peasy': 'produce',
react: 'React',
redux: 'Redux',
};
draft.output.name = titleCase(packageJson.name.replace(/-/g, ' ')).replace(
/ /g,
'',
);
draft.plugins.push(fileSize(), resolve(), commonjs());
});
module.exports = [
// Universal module definition (UMD) build, unminified, development
produce(commonUMD(baseConfig), draft => {
draft.output.file = `dist/${packageJson.name}.umd.development.js`;
draft.plugins = [
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
...draft.plugins,
];
}),
// Universal module definition (UMD) build, minified, production
produce(commonUMD(baseConfig), draft => {
draft.output.file = `dist/${packageJson.name}.umd.js`;
draft.plugins = [
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
...draft.plugins,
uglify(),
];
}),
// ESM build
produce(baseConfig, draft => {
draft.output.format = 'esm';
draft.output.file = `dist/${packageJson.name}.esm.js`;
}),
// CJS build
produce(baseConfig, draft => {
draft.output.format = 'cjs';
draft.output.file = `dist/${packageJson.name}.cjs.js`;
}),
];