-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup-terser.mjs
36 lines (30 loc) · 962 Bytes
/
rollup-terser.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
/*
The popular `rollup-terser-plugin` does not work well with Yarn PnP; its
reliance on `jest-worker` makes the build hang — probably related to
https://github.com/facebook/jest/issues/12060. This file provides a
simpler plugin that invokes Terser without Jest workers.
*/
import { minify } from 'terser';
function terser(terserOptions = {}) {
return {
name: 'terser',
async renderChunk(code, _chunk, outputOptions) {
const defaultOptions = {
sourceMap: !!outputOptions.sourcemap,
};
// eslint-disable-next-line default-case
switch (outputOptions.format) {
case 'es':
case 'esm':
defaultOptions.module = true;
break;
case 'cjs':
defaultOptions.toplevel = true;
break;
}
const effectiveTerserOptions = { ...defaultOptions, ...terserOptions };
return await minify(code, effectiveTerserOptions);
},
};
}
export default terser;