Webpack exclude Uglify

I used mqtt.js in my project, by installing npm install mqtt --save ,my app is react based and I’m using webpack for bundling. I imported connect from mqtt library as:

 import {connect} from 'mqtt';

And used connect, in develop mode everything are good but when I wanna build my project, I use webpack -p command so webpack begin to build production version, then I got this error:

 ERROR in server.js from UglifyJs
 Unexpected token: name (zlibLimiter) [server.js:1572,4]

The server.js is my bundle file name for production version, I tested to comment import {connect} from 'mqtt'; and tried to build and the build error vanished, it is very weird for me, because these project is built in damn windows 10 but in Linux(Ubuntu) and Mac OSX has this error.

I decided to exclude the mqtt uglify so use the uglify plugin and the exclude:

        new UglifyJsPlugin({
            exclude: `${srcDir}/app/public/mqtt.jsx`,
            uglifyOptions: {
                compress: {
                    warnings: false,
                    screw_ie8: true,
                    drop_console: true,
                    drop_debugger: true
                output: {
                    comments: false,
                    beautify: false,

But it doesn’t attention to my exclude and still show the error in build version, I also exclude like this: exclude: [/(node_modules\/)(?!mqtt)/,`${srcDir}/app/public/mqtt.jsx`] , but it doesn’t attention to my exclude and still show the error, is it webpack bug?

How I can fix this ?

Author: Fantashit

2 thoughts on “Webpack exclude Uglify

  1. It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I’m closing this. Please either update the issue with the template and reopen, or open a new issue.

  2. I don’t know why you are such an annoyance, sometime close my issues for just be a question, something you don’t know the answer and then close my issue, today even don’t read my issue, just close for damn template? oh man, good luck, have a good feature with this behavior.

Comments are closed.