-
Notifications
You must be signed in to change notification settings - Fork 103
/
rollup.config.js
executable file
·143 lines (135 loc) · 3.38 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
('use strict');
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const stripBanner = require('rollup-plugin-strip-banner');
const { terser } = require('rollup-plugin-terser');
const packageJson = require('./package.json');
const baseConfig = {
input: './src/index.js',
external: [
...Object.keys(packageJson.peerDependencies),
...Object.keys(packageJson.dependencies),
'prop-types',
],
plugins: [
resolve(),
commonjs({
include: /node_modules/,
namedExports: {
'react/index.js': [
'Children',
'Component',
'PureComponent',
'Fragment',
'PropTypes',
'createElement',
],
'react-dom/index.js': ['render'],
'react-is/index.js': ['isForwardRef'],
},
}),
babel({
babelrc: false,
exclude: ['node_modules/**'],
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['extends browserslist-config-carbon'],
},
},
],
'@babel/preset-react',
],
plugins: [
'dev-expression',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
],
}),
stripBanner(),
],
};
const umdExternalDependencies = Object.keys(
packageJson.peerDependencies
).filter((dependency) => dependency !== 'carbon-components');
const umdBundleConfig = {
input: baseConfig.input,
external: [...umdExternalDependencies, 'prop-types'],
output: {
name: 'WfpUiReact',
format: 'umd',
globals: {
classnames: 'classNames',
'prop-types': 'PropTypes',
react: 'React',
'react-dom': 'ReactDOM',
'@wfp/icons': '@wfp/icons',
},
},
};
module.exports = [
// TODO: update configuration to correctly support tree-shaking for React
// components. See:
// https://github.com/carbon-design-system/carbon/issues/5442
// Generates the following bundles:
// ESM: es/index.js
// CommonJS: lib/index.js
{
...baseConfig,
output: [
{
format: 'esm',
file: 'es/index.js',
},
{
format: 'cjs',
file: 'lib/index.js',
},
],
},
// Generate the development UMD bundle:
// UMD: umd/carbon-components-react.js
{
...umdBundleConfig,
plugins: [
...baseConfig.plugins,
replace({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
output: {
...umdBundleConfig.output,
file: 'umd/wfp-ui-react.js',
},
},
// Generate the production UMD bundle:
// UMD: umd/carbon-components-react.min.js
{
...umdBundleConfig,
plugins: [
...baseConfig.plugins,
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
terser(),
],
output: {
...umdBundleConfig.output,
file: 'umd/wfp-ui-react.min.js',
},
},
];