javascript - Webpack gzip compressed bundle not being served, the uncompressed bundle is -


i trying out webpack first time. i've been using gulp browserify time , pretty comfortable it. @ point, i'm testing out couple of webpack plugins. namely compression-webpack-plugin. i've never used compression before, bare me if i'm making noob mistake.

below webpack.config.js. result main.js, main.js.gz, main.css , index.html. main.js injected index.html, if open index.html in browser, serves uncompressed main.js, not compressed main.js.gz. had read wouldn't need include .gz extension in script tag, , html-webpack-plugin doesn't include it, figured things working correctly, yet uncompressed main.js served, rather compressed one.

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()   ] }; 

to load main.js.gz instead of main.js in case of included main.js in script-tag, need configure web-server (apache, nginx, etc.)

remember configuration should load .js.gz or .js depend on if browser accepts gzip. web-server can check in http request header accept-encoding: gzip, deflate

in browser devtools see main.js in cases.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -