-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
100 lines (96 loc) · 3.33 KB
/
rollup.config.js
File metadata and controls
100 lines (96 loc) · 3.33 KB
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
const path = require('path');
const commonjs = require('rollup-plugin-commonjs');
const replace = require('rollup-plugin-replace');
const nodeResolve = require('rollup-plugin-node-resolve');
const sourceMaps = require('rollup-plugin-sourcemaps');
const filesize = require('rollup-plugin-filesize');
const copy = require('rollup-plugin-copy');
const { terser } = require('rollup-plugin-terser');
process.env.NODE_ENV = 'production';
function createConfig(env, module) {
const isProd = env === 'production';
return {
input: 'compiled/index.js',
external:
module === 'umd'
? ['react', 'prop-types', 'react-formutil', 'antd-mobile']
: id => !id.startsWith('.') && !path.isAbsolute(id),
output: {
file: `dist/react-am-formutil.${module}.${env}.js`,
format: module,
name: 'ReactAmFormutil',
exports: 'named',
sourcemap: !isProd,
globals: {
react: 'React',
'prop-types': 'PropTypes',
'react-formutil': 'ReactFormutil',
'antd-mobile': 'AntdMobile'
}
},
treeshake: {
pureExternalModules: true
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(env)
}),
nodeResolve(),
commonjs({
include: /node_modules/
}),
sourceMaps(),
isProd &&
terser({
sourcemap: true,
output: { comments: false },
compress:
module === 'umd'
? {
warnings: false,
comparisons: false,
keep_infinity: true
}
: false,
warnings: false,
mangle: {
keep_classnames: true,
keep_fnames: true,
// https://github.com/ant-design/babel-plugin-import/issues/282
reserved: [
'List',
'Modal',
'Checkbox',
'DatePicker',
'DatePickerView',
'ImagePicker',
'InputItem',
'Picker',
'PickerView',
'Radio',
'Range',
'Slider',
'Switch',
'TextareaItem'
]
},
ecma: 5,
ie8: false,
toplevel: module !== 'umd'
}),
filesize(),
copy({
targets: [`npm/index.${module}.js`],
verbose: true
})
].filter(Boolean)
};
}
module.exports = [
createConfig('development', 'cjs'),
createConfig('production', 'cjs'),
createConfig('development', 'umd'),
createConfig('production', 'umd'),
createConfig('development', 'esm'),
createConfig('production', 'esm')
];