This repository has been archived by the owner on Nov 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
95 lines (83 loc) · 2.45 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
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
import nodeResolve from '@rollup/plugin-node-resolve'
import nodeGlobals from 'rollup-plugin-node-globals'
import replace from '@rollup/plugin-replace'
const packageDir = path.resolve(__dirname)
const name = 'vuex-light'
const packageResolve = p => path.resolve(packageDir, p)
const defaultFormats = ['esm-bundler', 'esm-browser', 'cjs', 'global']
const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',')
const finalFormats = inlineFormats || defaultFormats
const defaultModes = ['development', 'production']
const inlineModes = process.env.MODES && process.env.MODES.split(',')
const finalModes = inlineModes || defaultModes
let hasChecked = false
const outputConfigs = {
'esm-bundler': {
format: 'es',
file: packageResolve(`dist/index.esm-bundler.js`),
},
'esm-browser': {
format: 'es',
file: packageResolve(`dist/index.esm-browser.js`),
},
cjs: {
format: 'cjs',
file: packageResolve(`dist/index.cjs.js`),
},
global: {
format: 'iife',
file: packageResolve(`dist/index.global.js`),
},
}
function createConfig({ format, mode, outputConfig }) {
const isBundler = /bundler/.test(format)
const isGlobal = /global/.test(format)
const isDev = mode === 'development' || isBundler
const finalConfig = {
input: packageResolve('src/index.ts'),
external: isBundler ? ['vue'] : [],
output: {
...outputConfig,
globals: {
vue: 'Vue',
},
name: isGlobal ? 'VueCompositionUi' + toPascalCase(name) : undefined,
file: isDev ? outputConfig.file : outputConfig.file.replace(/\.js$/, '.prod.js'),
},
plugins: [
ts({
checked: hasChecked === false,
}),
nodeResolve(),
nodeGlobals(),
replace({
preventAssignment: true,
__DEV__: isBundler ? `(process.env.NODE_ENV !== 'production')` : isDev,
}),
isDev ? undefined : terser(),
],
}
hasChecked = true
return finalConfig
}
const configs = finalFormats
.map(format =>
finalModes.map(mode =>
createConfig({
format,
mode,
outputConfig: outputConfigs[format],
}),
),
)
.reduce((flattedConfigs, configs) => flattedConfigs.concat(...configs), [])
function toPascalCase(string) {
return string
.split('-')
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
.join('')
}
export default configs