Skip to content

Commit b0bd23b

Browse files
committed
Only run compression on prod builds
1 parent 7981156 commit b0bd23b

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const ngtools = require("@ngtools/webpack");
22
const webpackMerge = require("webpack-merge");
33
const commonPartial = require("./webpack/webpack.common");
44
const clientPartial = require("./webpack/webpack.client");
5+
const clientProdPartial = require("./webpack/webpack.client.prod");
56
const serverPartial = require("./webpack/webpack.server");
67
const prodPartial = require("./webpack/webpack.prod");
78
const { getAotPlugin } = require("./webpack/webpack.aot");
@@ -25,7 +26,7 @@ module.exports = function (options, webpackOptions) {
2526
});
2627

2728
if (options.aot) {
28-
clientConfig = webpackMerge({}, clientConfig, prodPartial);
29+
clientConfig = webpackMerge({}, clientConfig, webpackMerge({}, clientProdPartial, prodPartial));
2930
serverConfig = webpackMerge({}, serverConfig, prodPartial);
3031
}
3132

webpack/webpack.client.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
const path = require("path");
22
const webpack = require("webpack");
33
const HtmlWebpackPlugin = require("html-webpack-plugin");
4-
const HtmlWebpackExcludeAssetsPlugin = require("html-webpack-exclude-assets-plugin");
4+
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
55
const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin");
6-
const CompressionPlugin = require("compression-webpack-plugin");
7-
const BrotliPlugin = require("brotli-webpack-plugin");
86

97
const { CommonsChunkPlugin } = require("webpack").optimize;
108

@@ -35,19 +33,6 @@ module.exports = {
3533
},
3634
"target": "web",
3735
"plugins": [
38-
new CompressionPlugin({
39-
"asset": "[path].gz[query]",
40-
"algorithm": "gzip",
41-
"test": /\.js$|\.css$/,
42-
"threshold": 1024,
43-
"minRatio": 0.8
44-
}),
45-
new BrotliPlugin({
46-
"asset": "[path].br[query]",
47-
"test": /\.js$|\.css$/,
48-
"threshold": 1024,
49-
"minRatio": 0.8
50-
}),
5136
new HtmlWebpackPlugin({
5237
"template": "./src/index.pug",
5338
"filename": "./index.html",

webpack/webpack.client.prod.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const CompressionPlugin = require("compression-webpack-plugin");
2+
const BrotliPlugin = require('brotli-webpack-plugin');
3+
4+
/**
5+
* This is a client prod config which should be merged on top of common config
6+
*/
7+
module.exports = {
8+
"plugins": [
9+
new CompressionPlugin({
10+
"asset": "[path].gz[query]",
11+
"algorithm": "gzip",
12+
"test": /\.js$|\.css$/,
13+
"threshold": 1024,
14+
"minRatio": 0.8
15+
}),
16+
new BrotliPlugin({
17+
"asset": "[path].br[query]",
18+
"test": /\.js$|\.css$/,
19+
"threshold": 1024,
20+
"minRatio": 0.8
21+
})
22+
]
23+
};

0 commit comments

Comments
 (0)