-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
99 lines (93 loc) · 1.9 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 { existsSync } from 'node:fs';
import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import css from 'rollup-plugin-css-only';
import terser from '@rollup/plugin-terser';
import json from '@rollup/plugin-json';
import { getManifest } from './src/assets/manifest.js';
const isProd = !process.env.ROLLUP_WATCH;
const extensions = [
'.ts',
'.tsx',
];
const plugins = [
nodeResolve({
extensions,
browser: true,
}),
json({
preferConst: true,
}),
babel({
babelHelpers: 'bundled',
extensions,
presets: [
[
'@babel/preset-typescript',
{
optimizeConstEnums: true,
},
],
'jsx-dom-runtime/babel-preset',
],
}),
isProd && terser({
ecma: 2020,
module: true,
toplevel: true,
compress: {
ecma: 2020,
module: true,
comparisons: false,
inline: 2,
drop_console: true,
passes: 3,
toplevel: true,
unsafe: true,
pure_getters: true,
unsafe_arrows: true,
},
}),
]
.filter(Boolean);
const emptyDir = async (path) => {
if (existsSync(path)) await rm(path, { recursive: true });
await mkdir(path);
};
await emptyDir('./build');
await Promise.all([
cp('./static', './build', { recursive: true }),
writeFile('./build/manifest.json', getManifest(isProd)),
]);
export default [
{
input: './src/popup/main.tsx',
output: {
file: './build/popup.js',
format: 'es',
},
plugins: [
css({
output: 'popup.css',
}),
...plugins,
],
},
{
input: './src/content/index.ts',
output: {
file: './build/content.js',
format: 'es',
},
plugins,
},
{
input: './src/module/index.ts',
output: {
file: './build/module.js',
format: 'iife',
},
plugins,
},
];