-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminifyBundles.ts
28 lines (25 loc) · 926 Bytes
/
minifyBundles.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
import { minify } from 'terser';
const minifyBundles = () => {
return {
name: 'minifyBundles',
async generateBundle(_options: any, bundle: any) {
for (const key in bundle) {
if (bundle[key].type === 'chunk' && !key.includes('customFormEditor')) {
const minifyCode = await minify(bundle[key].code, { sourceMap: false });
bundle[key].code = minifyCode.code;
} else if (bundle[key].type === 'chunk' && key.includes('customFormEditor')) {
bundle[key].code = bundle[key].code.replaceAll('formFields2', 'formFields');
const minifyCode = await minify(bundle[key].code, {
mangle: {
reserved: ['RangeField', 'formFields.register', 'formFields']
},
sourceMap: false,
});
bundle[key].code = minifyCode.code;
}
}
return bundle;
},
};
};
export default minifyBundles;