Skip to content

Commit

Permalink
Allow specifying number of workers per bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Sep 16, 2018
1 parent 67d7519 commit 424d773
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 128 deletions.
42 changes: 24 additions & 18 deletions index.js
Expand Up @@ -6,31 +6,37 @@ function uglify(userOptions = {}) {
throw Error("sourceMap option is removed, use sourcemap instead");
}

const options = Object.assign({}, userOptions, {
const minifierOptions = Object.assign({}, userOptions, {
sourceMap: userOptions.sourcemap !== false,
sourcemap: undefined
sourcemap: undefined,
numWorkers: undefined
});

return {
name: "uglify",

renderStart() {
this.worker = new Worker(require.resolve("./transform.js"), {
numWorkers: userOptions.numWorkers
});
},

renderChunk(code) {
const worker = new Worker(require.resolve("./transform.js"));

return worker
.transform(code, options)
.then(result => {
worker.end();
return result;
})
.catch(error => {
worker.end();
const { message, line, col: column } = error;
console.error(
codeFrameColumns(code, { start: { line, column } }, { message })
);
throw error;
});
return this.worker.transform(code, minifierOptions).catch(error => {
const { message, line, col: column } = error;
console.error(
codeFrameColumns(code, { start: { line, column } }, { message })
);
throw error;
});
},

generateBundle() {
this.worker.end();
},

renderError() {
this.worker.end();
}
};
}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -26,18 +26,18 @@
"dependencies": {
"@babel/code-frame": "^7.0.0",
"jest-worker": "^23.2.0",
"uglify-js": "^3.4.8"
"uglify-js": "^3.4.9"
},
"peerDependencies": {
"rollup": ">=0.65.0 <1"
"rollup": ">=0.66.0 <1"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/core": "^7.0.1",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"jest": "^23.5.0",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"prettier": "^1.14.2",
"rollup": "^0.65.0"
"rollup": "^0.66.0"
}
}

0 comments on commit 424d773

Please sign in to comment.