Skip to content

Commit

Permalink
feat: 支持传参
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Nov 10, 2020
1 parent 1dfa5d0 commit c2fb1f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpbuild",
"version": "1.4.6",
"version": "1.4.7",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/plugin/minifyPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ function clearPool() {
}, 1000);
}

function minifyJS(contents) {
function minifyJS(contents, options) {
const opts = JSON.parse(options);
const UglifyJS = require('uglify-js');
const result = UglifyJS.minify(contents);
const result = UglifyJS.minify(contents, typeof opts === 'object' ? opts : undefined);
if (result.error) {
console.error('[MinifyPlugin]', result.error);
throw result.error;
Expand Down Expand Up @@ -70,7 +71,10 @@ module.exports = class MinifyPlugin {
// if (result.error) console.error('[MinifyPlugin]', result.error);
// if (result.warnings) console.warn('[MinifyPlugin]', result.warnings);
// asset.contents = result.code;
asset.contents = await pool.exec(minifyJS, [asset.contents]);
asset.contents = await pool.exec(minifyJS, [
asset.contents,
JSON.stringify(this.js)
]);
} else if (/\.json$/.test(asset.outputFilePath) && this.json) {
// asset.contents = jsonminify(asset.contents).toString();
asset.contents = await pool.exec(minifyJSON, [asset.contents]);
Expand Down

0 comments on commit c2fb1f7

Please sign in to comment.