1 | "use strict";
|
2 |
|
3 | const minify = async options => {
|
4 | const minifyFns = typeof options.minify === "function" ? [options.minify] : options.minify;
|
5 | const result = {
|
6 | code: options.input,
|
7 | warnings: [],
|
8 | errors: []
|
9 | };
|
10 |
|
11 | for (let i = 0; i <= minifyFns.length - 1; i++) {
|
12 | const minifyFn = minifyFns[i];
|
13 | const minifyOptions = Array.isArray(options.minimizerOptions) ? options.minimizerOptions[i] : options.minimizerOptions;
|
14 |
|
15 | const minifyResult = await minifyFn({
|
16 | [options.name]: result.code
|
17 | }, minifyOptions);
|
18 |
|
19 | if (Object.prototype.toString.call(minifyResult) === "[object Object]" && minifyResult !== null && "code" in minifyResult) {
|
20 | result.code = minifyResult.code;
|
21 | result.warnings = result.warnings.concat(minifyResult.warnings || []);
|
22 | result.errors = result.errors.concat(minifyResult.errors || []);
|
23 | } else {
|
24 | result.code = minifyResult;
|
25 | }
|
26 | }
|
27 |
|
28 | return result;
|
29 | };
|
30 |
|
31 | async function transform(options) {
|
32 |
|
33 |
|
34 |
|
35 | options = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
36 | return minify(options);
|
37 | }
|
38 |
|
39 | module.exports.minify = minify;
|
40 | module.exports.transform = transform; |
\ | No newline at end of file |