UNPKG

911 BJavaScriptView Raw
1const {minify} = require('terser');
2
3const terserOptions = {
4 sourceMap: true,
5 mangle: {
6 // Pass true to work around the Safari 10 loop iterator bug "Cannot
7 // declare a let variable twice".
8 // https://bugs.webkit.org/show_bug.cgi?id=171041
9 safari10: true,
10 },
11 // Set this option to true to work around the Safari 10/11 await bug.
12 // https://bugs.webkit.org/show_bug.cgi?id=176685
13 output: {
14 safari10: true,
15 },
16};
17
18/**
19 * Chunk transformer function called for each Rollup output chunk file.
20 * @param {string} source Source code.
21 * @return {Object}
22 */
23const transformChunk = function(source) {
24 const result = minify(source, terserOptions);
25
26 if (result.error) {
27 throw result.error;
28 }
29
30 return result;
31};
32
33module.exports = function() {
34 return {
35 name: 'minify',
36 transformChunk: transformChunk,
37 };
38};