Skip to content

Commit

Permalink
feat: pass the terserOptions to the minify option (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 11, 2020
1 parent defde64 commit 4bd622c
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 99 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -304,8 +304,13 @@ module.exports = {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
myCustomOption: true,
},
// Can be async
minify: (file, sourceMap) => {
minify: (file, sourceMap, minimizerOptions) => {
// The `minimizerOptions` option contains option from the `terserOptions` option
// You can use `minimizerOptions.myCustomOption`
const extractedComments = [];

// Custom logic for extract comments
Expand Down
12 changes: 9 additions & 3 deletions src/minify.js
Expand Up @@ -141,14 +141,20 @@ const buildComments = (extractComments, terserOptions, extractedComments) => {
};

async function minify(options) {
const { name, input, inputSourceMap, minify: minifyFn } = options;
const {
name,
input,
inputSourceMap,
minify: minifyFn,
minimizerOptions,
} = options;

if (minifyFn) {
return minifyFn({ [name]: input }, inputSourceMap);
return minifyFn({ [name]: input }, inputSourceMap, minimizerOptions);
}

// Copy terser options
const terserOptions = buildTerserOptions(options.minimizerOptions);
const terserOptions = buildTerserOptions(minimizerOptions);

// Let terser generate a SourceMap
if (inputSourceMap) {
Expand Down

0 comments on commit 4bd622c

Please sign in to comment.