Answer the question
In order to leave comments, you need to log in
Why is the final bundle not compressed in webpack2+uglifyjs-webpack-plugin?
bundle.js just doesn't compress. I do not know why. It seems that uglifyjs has been added to the plugins.
Here is webpack.config.js:
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
entry: "./src/index",
output: {
filename: "bundle.js",
path: path.join(__dirname, "dist")
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: { presets: ['stage-3', 'react'] }
}, {
test: /\.css$/,
include: path.join(__dirname, "src", "styles", "css"),
use: ['style-loader', 'css-loader']
}, {
test: /\.(scss|sass)$/,
include: path.join(__dirname, "src", "styles", "sass"),
use: ['style-loader', 'css-loader', 'sass-loader',]
},
{ test: /\.(png|svg|jpg|jpeg|gif)$/, use: ['file-loader',] },
{ test: /\.(woff|woff2|eot|ttf|otf)$/, use: ['file-loader',] },
]
},
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: './src/index.ejs',
title_: "webpack test react"
}),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true,
}),
new UglifyJSPlugin({
test: [".js"],
include: path.join(__dirname, "src"),
exclude: /node_modules/,
})
]
}
Answer the question
In order to leave comments, you need to log in
Why didn't the standard UglifyJsPlugin fit out of the box?
I have this config - everything works fine:
const { optimize } = require('webpack');
const { UglifyJsPlugin } = optimize;
new UglifyJsPlugin({
beautify: false,
comments: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true,
sequences: true,
booleans: true,
loops: true,
unused: true,
warnings: false,
drop_console: true,
unsafe: true
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question