我将翻译如下:
我得到了以下捆绑输出: 一切似乎都正常,但我不确定我是否以正确的方式进行了操作, 我不确定它是否实际上配置为使用bundle.js.gz。
我正在尝试使用CompressionPlugin压缩webpack包。以下是我的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。
gz
文件,因为这将在请求时生成,这并不理想。如果您使用nginx
或类似工具提供静态文件,则需要部署gz
文件。 - bamse