【发布时间】:2018-09-25 10:58:42
【问题描述】:
我正在尝试使用 CompressionPlugin 压缩 webpack 包。 在我的 webpack 设置下方
网络包
const path = require('path');
const webpack = require('webpack');
const CompressionPlugin = require("compression-webpack-plugin")
module.exports = {
entry: ['babel-polyfill', './src/client.js'],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname,'public')
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
}
}),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false,
beautify: false,
},
compress: {
screw_ie8: true,
warnings: false
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
],
watch: true,
module:{
loaders:[
{
test:/\.js$/,
exclude:/node_modules/,
loader: 'babel-loader',
query:{
presets: ['react','es2015','stage-1'],
},
},
],
},
};
www
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
index.ejs
<body>
<DIV id="app"><%- reactComponent -%></DIV>
<script>window.INITIAL_STATE=<%- initialState -%></script>
<SCRIPT src="/bundle.js"></SCRIPT>
</body>
</html>
似乎一切正常,但我不确定我是否以正确的方式进行操作, 我不确定它是否真的配置为使用 bundle.js.gz
【问题讨论】:
标签: javascript node.js reactjs webpack bundle