-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
128 lines (125 loc) · 3.33 KB
/
rollup.config.mjs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import path from 'node:path';
import pluginCommonjs from '@rollup/plugin-commonjs';
import nodeResolvePlugin from '@rollup/plugin-node-resolve';
import aliasPlugin from '@rollup/plugin-alias';
import { babel as babelPlugin } from '@rollup/plugin-babel';
import terserPlugin from '@rollup/plugin-terser';
import servePlugin from 'rollup-plugin-dev';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import copyPlugin from 'rollup-plugin-copy';
import { loadJSON, generatePluginOptions, generateBannerPlugin } from './utils/tools.mjs';
const envPlugin = process.env.NODE_ENV === 'production'
? [
// 代码压缩
terserPlugin({
maxWorkers: 4,
}),
]
: [
// 开发服务
...(process.env.NO_SERVER ? [] : [servePlugin({
dirs: ['dist'],
proxy: [
{ from: '/fe-ex-api/freport', to: 'https://www.test.meexs.dev/fe-ex-api/freport' }
]
})]),
// 拷贝开发文件
copyPlugin({
targets: [
{ src: 'template/index.html', dest: 'dist' },
],
copyOnce: true,
}),
];
const plugins = [
// banner 插件
generateBannerPlugin(path.resolve('./LICENSE.txt')),
// babel 插件
babelPlugin({
extensions: ['.ts'],
exclude: 'node_modules/**',
babelHelpers: 'bundled',
}),
// 路径别名插件
aliasPlugin({
entries: [
{
find: '@',
replacement: path.resolve('./src'),
},
{
find: '@root',
replacement: path.resolve('./'),
},
{
find: '@tys',
replacement: path.resolve('./types'),
},
],
customResolver: nodeResolvePlugin({
extensions: ['.ts', '.js'],
}),
}),
// 导出 commonjs 模块
pluginCommonjs({
extensions: ['.js', '.ts'],
}),
// 模块引入插件(import 和 require)
nodeResolvePlugin({
browser: true,
}),
// WebWorker 加载器
webWorkerLoader(),
...envPlugin,
];
const {
browser: pkgBrowser,
module: pkgModule
} = loadJSON(path.resolve('./package.json'));
export default [
// 核心模块配置 - 浏览器基础版
{
input: 'src/browser.ts',
output: [
{
file: pkgModule,
format: 'esm',
},
{
name: 'Monitor',
file: pkgBrowser,
format: 'umd',
},
],
plugins,
},
// 核心模块配置 - 浏览器 WebWorker 版
{
input: 'src/webworker.ts',
output: [
{
file: './dist/esm/webworker.js',
format: 'esm',
},
{
name: 'Monitor',
file: './dist/umd/webworker.js',
format: 'umd',
},
],
plugins,
},
// 核心模块配置 - nodejs 版
{
input: 'src/nodejs.ts',
output: [
{
file: './dist/esm/nodejs.js',
format: 'esm',
},
],
plugins,
},
// 插件配置
...generatePluginOptions(path.resolve('./src/publicPlugins/*/index.ts'), plugins),
];