-
Notifications
You must be signed in to change notification settings - Fork 38
/
rollup.config.js
95 lines (92 loc) · 2.4 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
const path = require('path')
const peerDepsExternal = require('rollup-plugin-peer-deps-external')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const vue = require('rollup-plugin-vue')
const babel = require('rollup-plugin-babel')
const postcss = require('rollup-plugin-postcss')
const { terser } = require('rollup-plugin-terser')
const replace = require('@rollup/plugin-replace')
function parseEnvironment (environment) {
return Object.fromEntries(environment.split(',').map(v => v.split(':')))
}
module.exports = ({ environment }) => {
const {
NODE_ENV,
FORMAT,
NAME: name,
GLOBAL: global,
INPUT: input
} = parseEnvironment(environment)
const isProd = NODE_ENV === 'production'
const isIIFE = FORMAT === 'iife'
const resolve = path.resolve
const resolveDir = p => resolve(__dirname, p)
const resolveOutput = p => resolve(resolveDir('dist'), p)
const FORMAT_OPTIONS = {
cjs: {
name: global,
format: 'cjs',
file: resolveOutput(`${name}.js`),
exports: 'named'
},
esm: {
name: global,
format: 'esm',
file: resolveOutput(`${name}.esm.js`)
},
iife: {
name: global,
format: 'iife',
file: resolveOutput(`${name}.global.js`),
exports: 'named'
}
}
return {
input: input,
output: FORMAT_OPTIONS[FORMAT],
treeshake: isProd,
plugins: [
!isIIFE &&
peerDepsExternal({
includeDependencies: true
}),
replace({
preventAssignment: true,
values: { 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) }
}),
vue({
css: !isProd,
normalizer: '~vue-runtime-helpers/dist/normalize-component.js'
}),
nodeResolve({
browser: true,
preferBuiltins: true
}),
isIIFE && babel({
babelrc: true,
runtimeHelpers: true,
extensions: ['.js', '.jsx', '.es6', '.es', '.mjs', '.vue']
}),
isIIFE &&
isProd &&
terser({
format: {
safari10: isProd,
preserve_annotations: true
},
compress: {
drop_console: isProd,
ecma: 2015,
pure_getters: true
}
}),
postcss({
extract: resolveOutput(`style/${name}.css`),
minimize: isProd,
sourceMap: false,
modules: false,
plugins: [require('autoprefixer')]
})
]
}
}