-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
75 lines (71 loc) · 1.97 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
import igniter from 'module-igniter';
import { mapValues } from 'lodash';
import pkg from './package.json';
const plug = igniter({ prefix: 'rollup-plugin-' });
const environment = process.env.NODE_ENV || 'development';
const prod = environment === 'production';
const watch = process.env.ROLLUP_WATCH;
const globals = {
'netlify-cms': 'CMS',
'create-react-class': 'createClass',
};
const external = Object.keys(globals);
const WATCH_FORMAT = process.env.WATCH_FORMAT || 'umd';
const formats = ['umd', 'iife', 'cjs', 'es'];
const isBrowser = format => format === 'umd' || format === 'iife';
const createOutput = (format = 'umd') => ({
sourcemap: prod,
name: pkg.library || pkg.name,
file: `lib/${format}/index.${prod ? 'min.js' : 'js'}`,
format,
globals: format === 'iife' ? mapValues(globals, o => `window['${o}']`) : globals,
});
export default (watch ? [WATCH_FORMAT] : formats).map(format => ({
input: 'src/index.js',
output: createOutput(format),
external,
plugins: [
...plug({
replace: { 'process.env.NODE_ENV': JSON.stringify(environment) },
'node-resolve': true,
commonjs: {
include: ['node_modules/**'],
},
babel: {
exclude: ['node_modules/**'],
presets: [
isBrowser(format) && [
'@babel/preset-react',
{
pragma: 'h',
},
],
].filter(Boolean),
plugins: [
isBrowser(format) && [
'transform-react-remove-prop-types',
{
removeImport: true,
additionalLibraries: ['react-immutable-proptypes'],
},
],
].filter(Boolean),
},
postcss: {
sourcemap: prod,
minimize: prod,
},
}),
...plug('strip', 'uglify', prod),
...plug(
{
serve: {
contentBase: ['public', `lib/${WATCH_FORMAT}`],
historyApiFallback: true,
},
livereload: true,
},
watch,
),
],
}));