-
Notifications
You must be signed in to change notification settings - Fork 769
/
pretty-minify.ts
27 lines (26 loc) · 977 Bytes
/
pretty-minify.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
import { BuildOptions } from '../../utils/options';
import { Plugin, OutputChunk } from 'rollup';
import terser from 'terser';
export function prettyMinifyPlugin(opts: BuildOptions): Plugin {
if (opts.isProd) {
return {
name: 'prettyMinifyPlugin',
generateBundle(_, bundles) {
Object.keys(bundles).forEach(fileName => {
const b = bundles[fileName] as OutputChunk;
if (typeof b.code === 'string') {
const minifyResults = terser.minify(b.code, {
compress: { hoist_vars: true, hoist_funs: true, ecma: 2018, keep_fnames: true, keep_classnames: true, module: true, arrows: true, passes: 2 },
output: { ecma: 2018, indent_level: 1, beautify: true, comments: false },
sourceMap: false,
});
if (minifyResults.error) {
throw minifyResults.error;
}
b.code = minifyResults.code;
}
});
},
};
}
}