-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
124 lines (111 loc) · 2.52 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 buble from '@rollup/plugin-buble'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
const banner = `/*!
* vuex v${pkg.version}
* (c) ${new Date().getFullYear()} Evan You
* @license MIT
*/`
const configs = [
{
input: 'src/index.js',
file: 'dist/vuex.esm-browser.js',
format: 'es',
browser: true,
env: 'development'
},
{
input: 'src/index.js',
file: 'dist/vuex.esm-browser.prod.js',
format: 'es',
browser: true,
env: 'production'
},
{
input: 'src/index.js',
file: 'dist/vuex.esm-bundler.js',
format: 'es',
env: 'development'
},
{
input: 'src/index.cjs.js',
file: 'dist/vuex.global.js',
format: 'iife',
env: 'development'
},
{
input: 'src/index.cjs.js',
file: 'dist/vuex.global.prod.js',
format: 'iife',
minify: true,
env: 'production'
},
{
input: 'src/index.cjs.js',
file: 'dist/vuex.cjs.js',
format: 'cjs',
env: 'development'
}
]
function createEntries() {
return configs.map((c) => createEntry(c))
}
function createEntry(config) {
const isGlobalBuild = config.format === 'iife'
const isBundlerBuild = config.format !== 'iife' && !config.browser
const isBundlerESMBuild = config.format === 'es' && !config.browser
const c = {
external: ['vue'],
input: config.input,
plugins: [],
output: {
banner,
file: config.file,
format: config.format,
exports: 'auto',
globals: {
vue: 'Vue'
}
},
onwarn: (msg, warn) => {
if (!/Circular/.test(msg)) {
warn(msg)
}
}
}
if (isGlobalBuild) {
c.output.name = c.output.name || 'Vuex'
}
if (!isGlobalBuild) {
c.external.push('@vue/devtools-api')
}
c.plugins.push(
replace({
preventAssignment: true,
__VERSION__: pkg.version,
__DEV__: isBundlerBuild
? `(process.env.NODE_ENV !== 'production')`
: config.env !== 'production',
__VUE_PROD_DEVTOOLS__: isBundlerESMBuild
? '__VUE_PROD_DEVTOOLS__'
: 'false'
})
)
if (config.transpile !== false) {
c.plugins.push(
buble({
transforms: { asyncAwait: false, forOf: false }
})
)
}
c.plugins.push(resolve())
c.plugins.push(commonjs())
if (config.minify) {
c.plugins.push(terser({ module: config.format === 'es' }))
}
return c
}
export default createEntries()