forked from acquitelol/azalea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
125 lines (110 loc) · 3.26 KB
/
rollup.config.ts
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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { typescriptPaths } from 'rollup-plugin-typescript-paths';
import { defineConfig, Plugin, RollupOptions } from 'rollup';
import { execSync } from 'child_process';
import { mkdirSync, existsSync } from 'fs';
import json from '@rollup/plugin-json';
import esbuild from 'rollup-plugin-esbuild';
import commonjs from 'rollup-plugin-commonjs';
import obfuscator, { ObfuscatorOptions } from 'javascript-obfuscator';
const obfuscateCode = (options?: ObfuscatorOptions): Plugin => ({
name: 'javascript-obfuscator',
transform(code) {
const obfuscationResult = obfuscator.obfuscate(code, options);
return {
code: obfuscationResult.getObfuscatedCode()
};
}
});
const copyExtension = (): Plugin => ({
name: 'copy-extension',
generateBundle() {
!existsSync('dist') && mkdirSync('dist');
switch (process.platform) {
case 'win32':
execSync('copy extension\\* dist\\');
break;
default:
execSync('cp -rf extension/* dist/');
}
}
});
const defineExtendedConfig = ({ plugins, ...options }: RollupOptions) => defineConfig({
onwarn(warning, warn) {
if (['MISSING_NAME_OPTION_FOR_IIFE_EXPORT', 'EVAL'].includes(warning.code)) return;
warn(warning);
},
watch: {
exclude: [
'dist/*',
'dist',
'rollup.config-*.mjs',
'package.json'
]
},
plugins: plugins ?? [
typescriptPaths({
preserveExtensions: true,
nonRelative: process.platform === 'darwin' ? false : true
}),
esbuild({ minify: true, target: 'ES2020' }),
obfuscateCode()
],
...options
});
export default [
defineExtendedConfig({
input: 'src/loader/index.ts',
output: [
{
file: 'dist/index.js',
format: 'iife',
inlineDynamicImports: true,
strict: false
}
],
plugins: [
typescriptPaths({
preserveExtensions: true,
nonRelative: process.platform === 'darwin' ? false : true
}),
json(),
esbuild({ minify: true, target: 'ES2020' }),
obfuscateCode()
]
}),
defineExtendedConfig({
input: 'src/loader/worker.ts',
output: [
{
file: 'dist/worker.js',
format: 'iife',
inlineDynamicImports: true,
strict: false
}
],
}),
defineExtendedConfig({
input: 'src/entry/index.ts',
output: [
{
file: 'dist/bundle.js',
format: 'iife',
inlineDynamicImports: true,
strict: false,
}
],
plugins: [
typescriptPaths({
preserveExtensions: true,
nonRelative: process.platform === 'darwin' ? false : true
}),
nodeResolve(),
commonjs(),
json(),
esbuild({ minify: true, target: 'ES2020' }),
obfuscateCode(),
copyExtension()
]
}),
];