我正在嘗試第一次使用Webpack。我一直在使用Gulp和Browserify一段時間,並且對它很滿意。在這一點上,我只是測試了幾個Webpack插件。即compression-webpack-plugin。我以前從來沒有使用過壓縮,如果我做出任何noob錯誤,那麼我就沒有使用過壓縮。未提供Webpack gzip壓縮包,未壓縮包是
下面是我的webpack.config.js。結果是我得到了一個main.js,main.js.gz,main.css和index.html。 main.js被注入到index.html中,但是如果我在瀏覽器中打開index.html,它會提供未壓縮的main.js,而不是壓縮的main.js.gz.我已經讀過,我不需要在腳本標記中包含.gz擴展名,並且html-webpack-plugin不包含它,所以我認爲事情工作正常,但未壓縮的main.js被服務,而不是壓縮的。
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
entry: './app/scripts/main.js',
output: {
path: path.join(__dirname, 'public'),
filename: '[name].js',
chunkFilename: '[id].js'
},
module: {
loaders: [
{test: /\.scss$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader')},
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
]
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: 'app/index.html',
inject: 'body'
}),
new ExtractTextPlugin('[name].css'),
new CompressionPlugin()
]
};
爲了加載PRE-ZIP(未生成)文件,我應該怎麼做? –
@RoyiNamir您需要編寫重寫規則 –
我沒有找到合適的規則來爲js文件提供gz文件 –