Backslash36
Backslash36

Reputation: 805

How can I achieve full minification with Webpack?

I have some trouble obtaining a truly minified bundle using webpack and uglify-loader.

Here is the setup

Content of app.js :

var React = require('react');
module.exports = 'just a string';

Content of webpack.config.js

module.exports = {
    context: __dirname,
    entry: './app.js',
    output: {
        path: __dirname,
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'uglify',
            }
        ]
    }
};

The problem

By looking at bundle.js, we can see that only partial minification has occured. The file is 1055 lines long, and is filled with a bunch of /******/.

How can I achieve true minification with webpack ? Using the uglify-loader is not mandatory.

Upvotes: 0

Views: 2700

Answers (1)

Aaleks
Aaleks

Reputation: 4343

You can use the UglifyJsPlugin from webpack; you specify it in the plugins section of your webpack configuration file:

  var webpack = require('webpack');
     plugins: [
         new webpack.optimize.UglifyJsPlugin({
             compress: {
                 screw_ie8: true,
                 warnings: false
             }
         })
     ]

For more informations about UglifyJsPlugin which minimize all JavaScript output of chunks. https://webpack.github.io/docs/list-of-plugins.html

Upvotes: 6

Related Questions