Javascript Web包开发服务器-服务gzip包
我已将添加到我的网页包配置中Javascript Web包开发服务器-服务gzip包,javascript,webpack,webpack-dev-server,Javascript,Webpack,Webpack Dev Server,我已将添加到我的网页包配置中 const webpack = require('webpack') const path = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') var CompressionPlugin = require('compression-webpack-plugin') module.exports = { context: path.join(__dirname,
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
var CompressionPlugin = require('compression-webpack-plugin')
module.exports = {
context: path.join(__dirname, '/src'),
entry: {
app: './app.js'
},
output: {
path: path.join(__dirname, '/dist'),
filename: '[name].bundle.js'
},
devServer: {
contentBase: path.join(__dirname, '/src')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader'
}]
},
{
test: /\.(woff|woff2|eot|ttf)$/,
use: ['url-loader?limit=10000']
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
favicon: 'favicon.ico',
template: 'index.html'
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|html)$/,
deleteOriginalAssets: true
})
]
}
现在,我有了一个app.bundle.js.gz
,而不是我的app.bundle.js
。没错
但是在index.html中,我仍然使用app.bundle.js
路径
当浏览器请求
app.bundle.js
时,如何告知提供gzip文件?在生产环境中,Apache或nginx等合适的web服务器可以做到这一点。您不能改用它吗?我们在生产环境中不使用dev服务器。我们想构建一个gzip包并将其发送到我们的生产服务器。我们可以在与webpack捆绑后使用gzip,但我认为有一个内置的解决方案。它有点复杂:webpack dev server
本身不提供捆绑文件,它从内存提供捆绑。但是,在开发模式下运行时,您始终可以禁用压缩插件。如果您想了解此答案的要点,请继续并将其作为一个答案发布。如果明天没有其他解决方案,我会接受它。@zemirco,面对同样的问题,有更新吗?