Add gzip compression

This commit is contained in:
LordMathis 2018-06-24 15:58:49 +02:00
parent 2716b342ed
commit fa22736644
4 changed files with 27 additions and 4 deletions

View File

@ -18,6 +18,7 @@
"async": "^2.5.0", "async": "^2.5.0",
"axios": "^0.17.0", "axios": "^0.17.0",
"express": "^4.13.4", "express": "^4.13.4",
"express-static-gzip": "^0.3.2",
"front-matter": "^2.2.0", "front-matter": "^2.2.0",
"jsonfile": "^4.0.0", "jsonfile": "^4.0.0",
"markdown-it": "^8.4.0", "markdown-it": "^8.4.0",
@ -40,6 +41,7 @@
"babel-preset-stage-0": "^6.5.0", "babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2", "babel-register": "^6.7.2",
"babel-runtime": "^6.26.0", "babel-runtime": "^6.26.0",
"compression-webpack-plugin": "^1.1.11",
"css-loader": "^0.28.11", "css-loader": "^0.28.11",
"css-modules-require-hook": "^4.0.6", "css-modules-require-hook": "^4.0.6",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",

View File

@ -1,4 +1,5 @@
require('babel-register'); require('babel-register');
var path = require('path');
var app = new (require('express'))(); var app = new (require('express'))();
var port = process.env.PORT || 3000; var port = process.env.PORT || 3000;
@ -38,12 +39,14 @@ if (process.env.NODE_ENV === 'development') {
app.use(hotDevMiddleware(compiler)) app.use(hotDevMiddleware(compiler))
} }
app.use(require('express').static('public'));
require('./utils/scanner')(); require('./utils/scanner')();
var api = require('./utils/api'); var api = require('./utils/api');
app.use("/api", api); app.use("/api", api);
var expressStaticGzip = require("express-static-gzip");
app.use("/static", expressStaticGzip(path.join(process.cwd(), '/public/static')));
var serverRender = require('./utils/serverRender'); var serverRender = require('./utils/serverRender');
app.get("*", serverRender); app.get("*", serverRender);

View File

@ -3,6 +3,7 @@ const webpack = require('webpack')
const UglifyJsPlugin = require("uglifyjs-webpack-plugin") const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin") const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin") const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin")
const CompressionPlugin = require("compression-webpack-plugin")
const config = { const config = {
mode: 'production', mode: 'production',
@ -67,7 +68,8 @@ const config = {
] ]
}, },
plugins: [ plugins: [
new MiniCssExtractPlugin({}) new MiniCssExtractPlugin({}),
new CompressionPlugin({})
] ]
} }

View File

@ -1253,7 +1253,7 @@ bytes@3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
cacache@^10.0.4: cacache@^10.0.1, cacache@^10.0.4:
version "10.0.4" version "10.0.4"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-10.0.4.tgz#6452367999eff9d4188aefd9a14e9d7c6a263460" resolved "https://registry.yarnpkg.com/cacache/-/cacache-10.0.4.tgz#6452367999eff9d4188aefd9a14e9d7c6a263460"
dependencies: dependencies:
@ -1613,6 +1613,16 @@ component-emitter@^1.2.1:
version "1.2.1" version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
compression-webpack-plugin@^1.1.11:
version "1.1.11"
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-1.1.11.tgz#8384c7a6ead1d2e2efb190bdfcdcf35878ed8266"
dependencies:
cacache "^10.0.1"
find-cache-dir "^1.0.0"
neo-async "^2.5.0"
serialize-javascript "^1.4.0"
webpack-sources "^1.0.1"
concat-map@0.0.1: concat-map@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@ -2283,6 +2293,12 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
dependencies: dependencies:
homedir-polyfill "^1.0.1" homedir-polyfill "^1.0.1"
express-static-gzip@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/express-static-gzip/-/express-static-gzip-0.3.2.tgz#89ede84547a5717de3146315f62dc996c071a88d"
dependencies:
serve-static "^1.12.3"
express@^4.13.4: express@^4.13.4:
version "4.16.3" version "4.16.3"
resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53" resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53"
@ -5753,7 +5769,7 @@ serialize-javascript@^1.4.0:
version "1.5.0" version "1.5.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe"
serve-static@1.13.2: serve-static@1.13.2, serve-static@^1.12.3:
version "1.13.2" version "1.13.2"
resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.2.tgz#095e8472fd5b46237db50ce486a43f4b86c6cec1" resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.2.tgz#095e8472fd5b46237db50ce486a43f4b86c6cec1"
dependencies: dependencies: