This is my first time testing Webpack. I have been using Gulp with Browserify for some time, and it is very convenient for me. At the moment, I'm just testing a couple of Webpack plugins. Namely, a compression plugin for webpack plugin. I have never used compression before, so naked with me if I make a noob mistake.
Below is my webpack.config.js. As a result, I get main.js, main.js.gz, main.css and index.html. Main.js is entered in index.html, but if I open index.html in my browser, it serves uncompressed main.js, not compressed main.js.gz. I read that I do not need to include the .gz extension in my script tag, and html-webpack-plugin does not include it, so I decided that everything worked correctly, but uncompressed main.js and not compressed.
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() ] };
javascript html webpack gzip compression
Patrick grimard
source share