-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.js
87 lines (78 loc) · 2.02 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
const rm = require('rimraf')
const path = require('path')
const ts = require('rollup-plugin-typescript2')
const terser = require('@rollup/plugin-terser')
const resolve = require('@rollup/plugin-node-resolve').default
const globals = require('rollup-plugin-node-globals')
const vue = require('rollup-plugin-vue')
const copy = require('rollup-plugin-copy')
const csso = require('csso')
const svg = require('rollup-plugin-svg')
const json = require('@rollup/plugin-json')
const babel = require('@rollup/plugin-babel')
rm.sync(path.resolve('dist/**/*'))
const packageName = 'vue-next-select'
const pascalCasePackageName = 'VueNextSelect'
const input = 'src/index.vue'
const formats = ['es', 'iife', 'cjs']
if (process.env.DEVELOPMENT) formats.splice(2)
const configs = []
formats.forEach(format => {
const config = {
input,
external: ['vue'],
plugins: [
json(),
vue(),
ts(),
svg({ base64: true }),
resolve(),
globals(),
babel({
babelHelpers: 'bundled',
extensions: ['.js', '.ts', '.vue'],
}),
],
output: {
globals: {
vue: 'Vue',
},
format,
name: pascalCasePackageName,
extend: true,
exports: 'auto',
},
}
configs.push({
...config,
output: {
...config.output,
file: path.resolve(`dist/${packageName}.${format}.js`),
},
})
configs.push({
...config,
plugins: [...config.plugins, terser()],
output: {
...config.output,
file: path.resolve(`dist/${packageName}.${format}.prod.js`),
},
})
})
const isWatchMode = process.env.npm_lifecycle_script.includes('--watch')
configs[configs.length - 1].plugins.push(
copy({
copyOnce: isWatchMode === false,
verbose: true,
targets: [
{
src: 'src/index.css',
dest: 'dist',
rename: (name, extension) => `${name}.min.${extension}`,
transform: content => csso.minify(content.toString()).css,
},
{ src: 'src/index.css', dest: 'dist' },
],
}),
)
module.exports = configs