-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
executable file
·107 lines (95 loc) · 2.76 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
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import buble from 'rollup-plugin-buble'
import commonjs from 'rollup-plugin-commonjs'
import vue from 'rollup-plugin-vue'
import eslint from 'rollup-plugin-eslint'
import uglify from 'rollup-plugin-uglify'
import sass from 'rollup-plugin-sass';
import replace from 'rollup-plugin-replace'
import copy from 'rollup-copy-plugin'
import filesize from 'rollup-plugin-filesize'
import postcss from 'postcss'
import csso from 'postcss-csso';
import { minify } from 'uglify-es'
import autoprefixer from 'autoprefixer'
const options = {
distName: 'snackbar-vue',
umdName: 'SnackbarVue',
transpiler: 'babel',
styles: 'extract',
external: ['vue']
}
const isProduction = process.env.NODE_ENV === `production`
const isDevelopment = process.env.NODE_ENV === `development`
const libPath = (isDevelopment
? `dist/${options.distName}.js`
: `dist/${options.distName}.min.js`)
const cssPath = (isDevelopment
? `dist/${options.distName}.css`
: `dist/${options.distName}.min.css`)
const sassConfig = {
include: [ '**/*.css', '**/*.scss' ],
options: {includePaths: ['node_modules']},
processor: css => postcss((isDevelopment
? [autoprefixer()]
: [autoprefixer(), csso()]))
.process(css)
.then(result => result.css)
}
if (isProduction && options.styles == 'extract') {
sassConfig.output = cssPath
} else {
sassConfig.insert = true
}
const config = {
input: 'libentry.js',
output: {
file: libPath,
format: 'umd',
name: options.umdName
},
external: options.external,
plugins: [
copy({
'src/styles/KFOlCnqEu92Fr1MmEU9fBBc4.woff2': 'dist/KFOlCnqEu92Fr1MmEU9fBBc4.woff2',
'src/styles/KFOmCnqEu92Fr1Mu4mxK.woff2': 'dist/KFOmCnqEu92Fr1Mu4mxK.woff2'
}),
replace({
'process.env.NODE_ENV': JSON.stringify( process.env.NODE_ENV )
}),
// eslint({ include: [ '**/*.js', '**/*.vue' ] }),
vue({ autoStyles: false, styleToImports: true }),
resolve({ jsnext: true, main: true, browser: true }),
sass(sassConfig),
commonjs ()
],
sourcemap: isDevelopment ? 'inline' : true
}
switch (options.transpiler){
case 'babel' :
config.plugins.push(babel())
break;
case 'buble' :
config.plugins.push(buble())
break;
case 'none':
default:
break
}
if (isProduction) {
config.plugins.push(replace({
'process.env.NODE_ENV': JSON.stringify( 'production' )
}))
config.plugins.push(uglify({}, minify))
config.plugins.push(filesize())
}
if (isDevelopment) {
// config.plugins.push(livereload())
// config.plugins.push(serve({
// contentBase: './public/',
// port: 8080,
// open: true
// }))
}
export default config