Skip to content

Commit

Permalink
Fix ncc'd version of terser not being used by terser webpack plugin (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Apr 28, 2020
1 parent f080931 commit af33ebc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/next/compiled/terser-webpack-plugin/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {
minify: terserMinify
} = require('terser');
} = require("next/dist/compiled/terser");

const buildTerserOptions = ({
ecma,
Expand Down
21 changes: 17 additions & 4 deletions packages/next/taskfile-ncc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ module.exports = function(task) {
minify: true,
...options,
}).then(({ code, assets }) => {
Object.keys(assets).forEach(key =>
Object.keys(assets).forEach(key => {
let data = assets[key].source

if (join(file.dir, key).endsWith('terser-webpack-plugin/worker.js')) {
data = Buffer.from(
data
.toString()
.replace(
`require('terser')`,
`require("${options.externals['terser']}")`
)
)
}

this._.files.push({
dir: join(file.dir, dirname(key)),
data,
base: basename(key),
data: assets[key].source,
dir: join(file.dir, dirname(key)),
})
)
})

if (options && options.packageName) {
writePackageManifest.call(this, options.packageName, file.base)
Expand Down

0 comments on commit af33ebc

Please sign in to comment.