-
Notifications
You must be signed in to change notification settings - Fork 20
/
rollup.config.js
99 lines (99 loc) · 2.49 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
import path from 'path';
import ts from 'rollup-plugin-typescript2';
// 将json 文件转换为ES6 模块
import json from '@rollup/plugin-json';
// 在node_模块中查找并绑定第三方依赖项
import resolve from '@rollup/plugin-node-resolve';
// 将CommonJS模块转换为ES6
import commonjs from '@rollup/plugin-commonjs';
// rollup babel插件
import babel from 'rollup-plugin-babel';
// 优化代码
import { terser } from 'rollup-plugin-terser';
// 加载样式文件
import styles from 'rollup-plugin-styles';
import dts from 'rollup-plugin-dts';
// 替换环境变量
// import replace from '@rollup/plugin-replace';
// 热更新服务
import livereload from 'rollup-plugin-livereload';
// 开发服务器
import serve from 'rollup-plugin-serve';
// 删除工具
import del from 'rollup-plugin-delete';
// import eslint from '@rollup/plugin-eslint'
import pkg from './package.json';
import gzip from 'rollup-plugin-gzip';
// 判断是是否为生产环境
// 开发环境or生产环境
const isPro = function () {
return process.env.NODE_ENV === 'production';
};
const extensions = ['.jsx', '.ts', '.tsx', '.less'];
export default [
{
input: path.resolve('./index.ts'),
output: [
{
file: pkg.unpkg,
format: 'umd',
name: pkg.jsname,
sourcemap: true,
},
{
file: pkg.module,
format: 'esm',
sourcemap: true,
},
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
],
plugins: [
resolve(), //快速查找外部模块
commonjs(), //将CommonJS转换为ES6模块
json(), //将json转换为ES6模块
styles(),
//ts编译插件
ts({
tsconfig: path.resolve(__dirname, './tsconfig.json'),
extensions: extensions,
}),
babel({
runtimeHelpers: true,
exclude: ['node_modules/**', 'src/plugins/**.js'],
}),
!isPro() &&
livereload({
watch: ['dist', 'examples', 'src/**/*'],
verbose: false,
}),
isPro() && terser(),
isPro() && gzip(),
!isPro() &&
serve({
open: false,
port: 9529,
contentBase: './',
openPage: '/examples/index.html',
}),
],
},
{
// 生成 .d.ts 类型声明文件
input: path.resolve('./index.ts'),
output: {
file: pkg.types,
format: 'es',
},
plugins: [
dts(),
del({
targets: ['./dist/src'],
hook: 'buildEnd',
}),
],
},
];