-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathrollup.config.js
80 lines (76 loc) · 1.77 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
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import postcss from 'rollup-plugin-postcss'
import resolve from 'rollup-plugin-node-resolve'
import replace from 'rollup-plugin-replace'
import { uglify } from 'rollup-plugin-uglify'
import url from 'rollup-plugin-url'
import svgr from '@svgr/rollup'
// 通过 mode 接口拿到 src/components 下的所有文件夹名作为打包后的模块
const fs = require('fs')
const path = require('path')
const componentDir = 'src/components'
const cModuleNames = fs.readdirSync(path.resolve(componentDir))
const cModuleMap = cModuleNames.reduce((prev, name) => {
prev[name] = `${componentDir}/${name}/index.js`
return prev
}, {})
const plugins = [
external(),
postcss(),
url(),
svgr(),
babel({
exclude: 'node_modules/**',
plugins: ['external-helpers']
}),
resolve(),
commonjs()
]
export default [
{
input: {
index: 'src/index.js',
...cModuleMap
},
output: [
{
dir: 'lib',
entryFileNames: '[name]/index.js',
format: 'cjs',
sourcemap: true
},
{
dir: 'es',
entryFileNames: '[name]/index.js',
format: 'es',
sourcemap: true
}
],
plugins,
experimentalCodeSplitting: true
},
{
input: 'src/index.js',
output: {
format: 'umd',
file: 'umd/datav.js',
name: 'datav'
},
plugins: [...plugins, replace({ 'process.env.NODE_ENV': '"development"' })]
},
{
input: 'src/index.js',
output: {
format: 'umd',
file: 'umd/datav.min.js',
name: 'datav'
},
plugins: [
...plugins,
replace({ 'process.env.NODE_ENV': '"production"' }),
uglify()
]
}
]