Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass the terserOptions to the minify option #311

Merged
merged 1 commit into from Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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