Webpack2 UglifyJsPlugin not working.

webpack.config.js

var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {

    entry: {
        vendor: ["pixi", 'pixi-particles'],
        app: ['./scss/main.scss', './js/main.js']
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist/',
        filename: 'app.js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                options: {
                    "presets": [
                        "es2015"
                    ]
                },
                include: [
                    "./js"
                ]
            },
            {
                test: /\.css$/,
                use: [
                    "style-loader", "css-loader"
                ]
            },
            {
                test: /\.(png|jpg|gif|svg|ttf)$/,
                loader: 'file-loader',
                options: {
                    name: '[name].[ext]?[hash]'
                }
            },
            {
                test: /\.scss$/,
                use: [
                    "style-loader", "css-loader", 'postcss-loader', "sass-loader"
                ]
            }
        ]
    },
    resolve: {
        alias: {
            'pixi': 'pixi.js/dist/pixi.min.js',
            'pixi-particles': 'pixi-particles/dist/pixi-particles.min.js'
        }
    },
    devtool: 'cheap-module-eval-source-map',
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendor",
            filename: "vendor.js",
            minChunks: Infinity
        }),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new HtmlWebpackPlugin({
            template: 'index.html',
            inject: 'head'
        })
    ]
};

if (process.env.NODE_ENV === 'prod') {

    module.exports.devtool = false;
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
                pure_funcs: ['console.log', 'window.console.log.apply']
            },
        }),
    ])
}

package.json
“build”: “cross-env NODE_ENV=prod webpack –progress -p”

And after I run command npm run build.

image

Codes didnt compressed.

Author: Fantashit

2 thoughts on “Webpack2 UglifyJsPlugin not working.

  1. Alright,I solved it single-handedly.Because I missed one .babelrc file,so babel-loader didnt work.

    {
      "presets": ["es2015"],
      "plugins": ["transform-runtime"],
      "comments": false
    }
    

Comments are closed.