forked from mater1996/vue-photo-zoom-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
88 lines (85 loc) · 2.41 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
const path = require('path')
const peerDepsExternal = require('rollup-plugin-peer-deps-external')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const commonjs = require('@rollup/plugin-commonjs')
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')
const { name } = require('./package.json')
function parseEnvironment (environment) {
return Object.fromEntries(environment.split(',').map(v => v.split(':')))
}
module.exports = ({ environment }) => {
const { NODE_ENV, FORMAT } = 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: 'VuePhotoZoomPro',
format: 'cjs',
file: resolveOutput(`${name}.js`),
exports: 'default'
},
esm: {
name: 'VuePhotoZoomPro',
format: 'esm',
file: resolveOutput(`${name}.esm.js`)
},
iife: {
name: 'VuePhotoZoomPro',
format: 'iife',
file: resolveOutput(`${name}.global.js`)
}
}
return {
input: 'src/vue-photo-zoom-pro.vue',
output: FORMAT_OPTIONS[FORMAT],
treeshake: isProd,
plugins: [
peerDepsExternal(),
replace({
preventAssignment: true,
values: { 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) }
}),
commonjs(),
vue({
css: !isProd,
normalizer: '~vue-runtime-helpers/dist/normalize-component.js'
}),
nodeResolve({
browser: true,
preferBuiltins: true
}),
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')]
})
]
}
}