-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
111 lines (106 loc) · 2.56 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
import svelte from 'rollup-plugin-svelte'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import { scss, postcss } from 'svelte-preprocess'
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano' // 优化css
import babel from 'rollup-plugin-babel'
import { uglify } from 'rollup-plugin-uglify'
import filesize from 'rollup-plugin-filesize'
import copy from 'rollup-plugin-copy'
import nodent from 'rollup-plugin-nodent' // 转async/await
import json from 'rollup-plugin-json'
import css from 'rollup-plugin-css-only'
const production = !process.env.ROLLUP_WATCH
const _autoprefixer = _ => {
return autoprefixer({
'overrideBrowserslist': [
'last 20 versions'
]
})
}
// "sirv-cli": "^0.4.4",
export default {
input: 'src/index.js',
output: {
sourcemap: false,
format: 'umd',
name: 'MdEditor',
file: !production ? 'public/dist/editor.js' : 'dist/editor.min.js',
},
plugins: [
json(),
svelte({
dev: !production,
css: css => {
css.write(!production ? 'public/dist/editor.css' : 'dist/editor.css',false)
},
preprocess:[
scss(),
postcss({
plugins: [
_autoprefixer(),
cssnano()
]
})
]
}),
css({ output:!production ? 'public/dist/reset.css' : 'dist/reset.css' }),
nodent({
promises: true,
noRuntime: true
}),
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
babel({
extensions: ['.js','.mjs','.html','.svelte'],
// exclude: ['node_modules/**'],
runtimeHelpers: true
}),
!production && livereload(),
production && filesize(),
production && terser(),
production && uglify(),
copy({
targets: [
{ src:[
'src/icon/iconfont.eot',
'src/icon/iconfont.svg',
'src/icon/iconfont.ttf',
'src/icon/iconfont.woff',
'src/icon/iconfont.woff2'
],dest:!production ? 'public/dist/icon' : 'dist/icon'},
]
}),
!production && serve({
open: true,
contentBase: 'public',
historyApiFallback: true,
host: 'localhost',
port: 9988
})
],
watch: {
clearScreen: false
}
}
// function serve() {
// let started = false
// return {
// writeBundle() {
// if (!started) {
// started = true
// require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
// stdio: ['ignore', 'inherit', 'inherit'],
// shell: true
// })
// }
// }
// }
// }