-
Notifications
You must be signed in to change notification settings - Fork 290
/
rollup.config.js
124 lines (119 loc) · 4.26 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import nodeResolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import inject from '@rollup/plugin-inject';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
import cssRollupConfigs from './build_helpers/cssRollup.config.js';
import pkg from './package.json';
// extract out the list of peer dependencies from package.json
const peerDependencies = Object.keys(pkg.peerDependencies || {});
export default [
// for CSS
...cssRollupConfigs,
// for CommonJS and ES6
{
input: 'src/index.js',
output: [
{
file: 'dist/cjs/fixed-data-table-2.js',
format: 'cjs',
sourcemap: true,
},
{
file: 'dist/es/fixed-data-table-2.js',
format: 'es',
sourcemap: true,
},
],
plugins: [
replace({
preventAssignment: true,
__DEV__: 'process.env.NODE_ENV !== "production"',
}),
nodeResolve(), // allow importing external modules (node modules)
babel({
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime'],
exclude: 'node_modules/**', // no need to include node_modules because libraries only distribute transpiled code
}),
commonjs({
include: 'node_modules/**', // allow importing common JS modules
}),
],
external: peerDependencies, // don't include peer dependencies in our bundle
},
// for UMD during development
{
input: 'src/index.js',
output: {
// NOTE (pradeep): I prefer this to be in "dist/umd" instead of just "dist/", but that'll break backward compatibility.
// I also prefer this to be named fixed-data-table-2.js, but that also breaks backward compatibility.
file: 'dist/fixed-data-table.js',
name: 'FixedDataTable',
format: 'umd',
globals: {
react: 'React', // react's UMD export name is 'React'
'react-dom': 'ReactDOM', // react-dom's UMD export name is 'ReactDOM'
},
sourcemap: true,
},
plugins: [
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('development'), // this bundle is always used in development mode
__DEV__: true,
}),
nodeResolve(), // allow importing external modules (node modules)
babel({
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime'],
exclude: 'node_modules/**', // no need to include node_modules because libraries only distribute transpiled code
}),
commonjs({
include: 'node_modules/**', // allow importing common JS modules
}),
inject({
global: 'global', // `global` is not defined in browsers, so we use a polyfill
}),
],
external: peerDependencies, // don't include peer dependencies in our bundle
},
// for UMD in production
{
input: 'src/index.js',
output: {
// NOTE (pradeep): I prefer this to be in "dist/umd" instead of just "dist/", but that'll break backward compatibility.
// I also prefer this to be named fixed-data-table-2.js, but that also breaks backward compatibility.
file: 'dist/fixed-data-table.min.js',
name: 'FixedDataTable',
format: 'umd',
globals: {
react: 'React', // react's UMD export name is 'React'
'react-dom': 'ReactDOM', // react-dom's UMD export name is 'ReactDOM'
},
sourcemap: true,
},
plugins: [
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'), // this bundle is always used in production mode
__DEV__: false,
}),
nodeResolve(),
babel({
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime'],
exclude: 'node_modules/**', // no need to include node_modules because libraries only distribute transpiled code
}),
commonjs({
include: 'node_modules/**', // allow importing of common JS modules
}),
inject({
global: 'global', // `global` is not defined in browsers, so we use a polyfill
}),
terser(), // minify because this bundle is for production usage
],
external: peerDependencies, // don't include peer dependencies in our bundle
},
];