-
Notifications
You must be signed in to change notification settings - Fork 22
/
rollup.config.js
54 lines (47 loc) · 1.26 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
import babel from 'rollup-plugin-babel'
import resolve from "@rollup/plugin-node-resolve";
import VuePlugin from 'rollup-plugin-vue'
import unassert from 'rollup-plugin-unassert';
import commonjs from "@rollup/plugin-commonjs"
import css from 'rollup-plugin-css-only' // 提取css,压缩能力不行
import CleanCSS from 'clean-css' // 压缩css
import {
writeFileSync
} from 'fs' // 写文件
import {
terser
} from 'rollup-plugin-terser'
const extensions = [".js"];
export default {
input: './src/index.js',
output: {
file: './dist/bundle.esm.js',
format: 'esm', //若打包commonjs
assetFileNames: "[name]-[hash][extname]"
},
external: ["vue", "@vue/compiler-sfc"],
plugins: [
resolve(),
babel({
exclude: "node_modules/**",
extensions,
runtimeHelpers: true,
}),
commonjs(),
VuePlugin({
css: false
}),
css({
output(style) {
// 压缩 css 写入 dist/vue-rollup-component-template.css
writeFileSync('./dist/index.css', new CleanCSS().minify(style).styles)
}
}),
// css: false 将<style>块转换为导入语句,rollup-plugin-css-only可以提取.vue文件中的样式
unassert(),
terser()
],
treeshake: {
moduleSideEffects: false,
}
}