-
-
Notifications
You must be signed in to change notification settings - Fork 163
Description
- Operating System: macOS 10.12.6
- Node Version: v10.14.2
- NPM Version: 6.8.0
- webpack Version: 4.29.6 (bug first appeared in 4.26.0 with the switch to terser)
- terser-webpack-plugin Version: 1.2.3
Expected Behavior
Webpack production mode emits valid javascript that can be executed by a browser. E.g.
(function(e){return e})`one`Actual Behavior
Webpack production mode is emitting invalid javascript. Specifically it's emitting an unnamed function (i.e. function() {...}) that is not syntactically valid. E.g.
function(e){return e}`one`Code
webpack.config.js
module.exports = {
mode: "production",
entry: `${__dirname}/src/index.js`,
output: {
path: `${__dirname}/build`,
filename: "repro.min.js"
}
};src/index.js
function tpl(str) {
return str;
}
const unused = tpl`one`;
// Uncomment the line below to work around the bug:
// const anotherUnused = tpl`two`;build/repro.min.js (webpack default wrappers removed for clarity)
function(e){return e}`one`You can see that a single unused tagged template literal is producing an unnamed function error. It can be worked around by referencing the template literal function multiple times but wasn't a bug before terser was introduced as the minification engine for webpack.
Interestingly enough, I was not able to reproduce the bug in terser (v3.16.1), which leads me to believe the bug exists in this plugin.
How Do We Reproduce?
I've created a really small repo which should help you reproduce the issue (instructions assume you're on a mac since it uses the open command to open the index file in a browser):
git clone [email protected]:jondlm/webpack-template-literal-bug.git
cd webpack-template-literal-bug
npm install
npm start