慕勒7123956
可以用UglifyJsPlugin压缩js和css,如果需要需要单独把css提取出来,可以用extract-text-webpack-pluginconst path = require("path");
const htmlWP = require("html-webpack-plugin");
const webpack = require("webpack");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
entry: "./src/script/main.js",
output: {
path: path.join(__dirname + "/dist"),
filename: "js/bundle.js"
},
module: {
rules: [{
test: /\.css$/,
use: [
"style-loader",
"css-loader"
]
},
{
test:/\.(png|svg|jpg|gif)$/,
use:[
"file-loader"
]
},
{
test:/\.js$/,
use:[
"babel-loader"
],
exclude: path.join(__dirname + "/node_modules"),
include: path.join(__dirname + "/src")
}],
},
plugins: [
new htmlWP({
filename: "index.html",
template: "index.html",
minify: {
collapseWhitespace: false,
removeComments: true
}
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [require("autoprefixer")({
browsers: ["last 5 versions"]
})]
}
}),
new UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
]
};