Skip to content

Commit 8f22699

Browse files
committed
feat(app): generate and serve pre-gzipped client files
(in prod)
1 parent 9a8bb89 commit 8f22699

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

Diff for: templates/app/_package.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"compression": "^1.7.1",
77
"core-js": "^2.5.0",
88
"express": "^4.13.3",
9+
"express-static-gzip": "~0.3.2",
910
"morgan": "^1.9.0",
1011
"body-parser": "^1.13.3",
1112
"method-override": "^2.3.10",
@@ -147,6 +148,7 @@
147148
"run-sequence": "^2.1.0",
148149
"lazypipe": "^1.0.1",
149150
<%# WEBPACK %>
151+
"compression-webpack-plugin": "^1.1.11",
150152
"webpack": "^4.12.0",
151153
"webpack-cli": "^3.0.6",
152154
"webpack-dev-server": "^3.1.4",

Diff for: templates/app/server/config/express.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import express from 'express';
6+
import expressStaticGzip from 'express-static-gzip';
67
import favicon from 'serve-favicon';
78
import morgan from 'morgan';
89
import compression from 'compression';
@@ -23,7 +24,7 @@ import sqldb from '../sqldb';
2324
let Store = require('connect-session-sequelize')(session.Store);<% } %>
2425

2526
export default function(app) {
26-
var env = app.get('env');
27+
var env = process.env.NODE_ENV;
2728

2829
if(env === 'development' || env === 'test') {
2930
app.use(express.static(path.join(config.root, '.tmp')));
@@ -36,6 +37,9 @@ export default function(app) {
3637

3738
app.set('appPath', path.join(config.root, 'client'));
3839
app.use(express.static(app.get('appPath')));
40+
if(env === 'production') {
41+
app.use("/", expressStaticGzip(app.get('appPath')));
42+
}
3943
app.use(morgan('dev'));
4044

4145
app.set('views', `${config.root}/server/views`);<% if(filters.html) { %>

Diff for: templates/app/webpack.make.js

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*eslint-env node*/
22
const _ = require('lodash');
3-
var webpack = require('webpack');
4-
var HtmlWebpackPlugin = require('html-webpack-plugin');
5-
var HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
6-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
7-
var fs = require('fs');
8-
var path = require('path');
3+
const CompressionPlugin = require('compression-webpack-plugin');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
6+
const path = require('path');
7+
const webpack = require('webpack');
98

109
module.exports = function makeWebpackConfig(options) {
1110
/**
@@ -311,18 +310,15 @@ module.exports = function makeWebpackConfig(options) {
311310
})
312311
];
313312

314-
if(!TEST) {
315-
// TODO(webpack4)
316-
// config.plugins.push(new CommonsChunkPlugin({
317-
// name: 'vendor',
318-
//
319-
// // filename: "vendor.js"
320-
// // (Give the chunk a different name)
321-
//
322-
// minChunks: Infinity
323-
// // (with more entries, this ensures that no other module
324-
// // goes into the vendor chunk)
325-
// }));
313+
if(BUILD) {
314+
config.plugins.push(
315+
new CompressionPlugin({}),
316+
// https://github.com/webpack-contrib/mini-css-extract-plugin
317+
new MiniCssExtractPlugin({
318+
filename: '[name].[hash].css',
319+
chunkFilename: '[id].[hash].css',
320+
}),
321+
);
326322
}
327323

328324
// Skip rendering app.html in test mode

0 commit comments

Comments
 (0)