-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.mjs
111 lines (105 loc) · 2.81 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import eslint from '@rollup/plugin-eslint';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import pkg from './package.json' assert { type: 'json' };
import json from '@rollup/plugin-json';
import filesize from 'rollup-plugin-filesize';
const isDevelopment = process.env.MODE.trim() === 'development';
const startServer = process.env.SERVE.trim() === 'true';
const input = process.env.INPUT.trim();
const rxjs = 'rxjs';
const minExtReg = /\.min\.js$/;
const umdPathReg = /\/umd\//;
const pathMap = {
umd: pkg.main,
umdDev: pkg.main.replace(minExtReg, '.js'),
esm: pkg.module,
esmDev: pkg.module.replace(minExtReg, '.js'),
iife: pkg.main
.replace(umdPathReg, '/render/')
.replace(minExtReg, '.iife.min.js'),
iifeDev: pkg.main
.replace(umdPathReg, '/render/')
.replace(minExtReg, '.iife.js'),
};
const config = {
input,
output: (startServer ? ['iife'] : ['esm', 'umd']).map((format) => {
return {
name: pkg.name,
sourcemap: isDevelopment,
file: isDevelopment ? pathMap[`${format}Dev`] : pathMap[format],
format,
globals: { rxjs },
};
}),
external: startServer ? [] : [...Object.keys(pkg.peerDependencies)],
plugins: [
...(isDevelopment && startServer
? [
eslint({
exclude: [
'node_modules/**',
'json/**',
'package.json',
'package-lock.json',
],
throwOnError: true,
}),
]
: [filesize()]),
resolve({
customResolveOptions: {
moduleDirectories: ['node_modules'],
},
preferBuiltins: true,
}),
commonjs(),
babel({
exclude: 'node_modules/**',
babelHelpers: 'bundled',
}),
...(isDevelopment
? startServer
? [
json({
exclude: ['node_modules/**'],
compact: true,
preferConst: true,
}),
serve({
open: true,
contentBase: ['dist'],
host: 'localhost',
port: '3030',
historyApiFallback: true,
}),
livereload({
watch: 'dist',
verbose: false,
}),
]
: []
: [
...(startServer
? [
json({
exclude: ['node_modules/**'],
compact: true,
preferConst: true,
}),
]
: []),
terser({
output: {
comments: false,
},
}),
]),
],
};
export default [config];