-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
96 lines (91 loc) · 1.92 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
// 识别commonjs类型的包,默认只支持导入ES6
import commonjs from '@rollup/plugin-commonjs';
// 支持import导入
import nodeResolve from '@rollup/plugin-node-resolve';
// TypeScript编译(TypeScript转JavaScript)
import typescript from 'rollup-plugin-typescript2';
// 支持加载Json文件
import json from '@rollup/plugin-json';
// 支持字符串替换, 比如动态读取package.json的version到代码
import replace from '@rollup/plugin-replace';
// 读取package.json
import pkg from './package.json';
// 压缩
import { terser } from "rollup-plugin-terser";
// 测试serve
import serve from 'rollup-plugin-serve';
const banner = `
/*!
* @dengfengwang/utils v${pkg.version}
*
* @author wangweiwei
*/
`;
// 插件列表
const plugins = [
json(),
replace({
__VERSION__: pkg.version,
__NAME__: pkg.name
}),
typescript({
exclude: 'node_modules/**',
rollupCommonJSResolveHack: false,
clean: true,
typescript: require('typescript')
}),
nodeResolve({
jsnext: true,
main: true,
browser: true
}),
commonjs({
include: 'node_modules/**'
}),
terser(),
];
// 是否停止Server
const SERVER_STOP = process.env.SERVER_STOP === 'true';
if(!SERVER_STOP) {
serve({
host: 'localhost',
port: 8000,
contentBase: ['lib', 'examples'],
})
}
// 输出文件列表
const output = [{
format: 'cjs',
file: pkg.main,
banner,
file: './lib/utils.cjs.js',
sourcemap: true
}, {
format: 'es',
file: pkg.module,
banner,
file: './lib/utils.es.js',
sourcemap: true,
}, {
format: 'umd',
name: '__video_metadata_thumbnails__',
file: pkg.browser,
banner,
file: './lib/utils.umd.js',
sourcemap: true
}, {
format: 'iife',
name: '__video_metadata_thumbnails__',
file: pkg.browser,
banner,
file: './lib/utils.iife.js',
sourcemap: true
}]
export default {
input: './src/index.ts',
output,
plugins,
watch: {
exclude: ['node_modules/**']
}
}