From 4c2a3d8df0d1a1fee48b0624b4b5a9a20db0d53e Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 17 May 2017 00:28:45 +0900 Subject: [PATCH] Compress an assets --- package.json | 3 ++- src/web/app/auth/view.pug | 2 +- src/web/app/client/script.js | 2 +- src/web/app/dev/view.pug | 2 +- webpack/plugins/compression.ts | 9 +++++++++ webpack/plugins/index.ts | 6 +++++- 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 webpack/plugins/compression.ts diff --git a/package.json b/package.json index 6666d65cd5..36d9fc711a 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "@types/websocket": "0.0.33", "chai": "3.5.0", "chai-http": "3.0.0", + "compression-webpack-plugin": "0.4.0", "css-loader": "0.28.1", "event-stream": "3.3.4", "gulp": "3.9.1", @@ -87,7 +88,7 @@ "stylus-loader": "3.0.1", "swagger-jsdoc": "1.9.4", "tslint": "5.2.0", - "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#8f4b45f4f814c04918382949b4bcaf7a8d910281", + "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", "webpack": "2.5.1" }, "dependencies": { diff --git a/src/web/app/auth/view.pug b/src/web/app/auth/view.pug index afa1e408f8..7fc4a2a70d 100644 --- a/src/web/app/auth/view.pug +++ b/src/web/app/auth/view.pug @@ -2,4 +2,4 @@ extends ../base block head meta(name='viewport' content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no') - script(src=`/assets/auth.${version}.ja.js` async defer) + script(src=`/assets/auth.${version}.ja.js.gz` async defer) diff --git a/src/web/app/client/script.js b/src/web/app/client/script.js index 465d3edb38..c069b0ee89 100644 --- a/src/web/app/client/script.js +++ b/src/web/app/client/script.js @@ -16,7 +16,7 @@ const app = isMobile ? 'mobile' : 'desktop'; // Load app script const script = document.createElement('script'); -script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`); +script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js.gz`); script.setAttribute('async', 'true'); script.setAttribute('defer', 'true'); head.appendChild(script); diff --git a/src/web/app/dev/view.pug b/src/web/app/dev/view.pug index 1a9a0e5bbd..9bba6c11c5 100644 --- a/src/web/app/dev/view.pug +++ b/src/web/app/dev/view.pug @@ -1,4 +1,4 @@ extends ../base block head - script(src=`/assets/dev.${version}.js` async defer) + script(src=`/assets/dev.${version}.ja.js.gz` async defer) diff --git a/webpack/plugins/compression.ts b/webpack/plugins/compression.ts new file mode 100644 index 0000000000..89703680c1 --- /dev/null +++ b/webpack/plugins/compression.ts @@ -0,0 +1,9 @@ +/** + * Compressor + */ + +const CompressionPlugin = require('compression-webpack-plugin'); + +export default () => new CompressionPlugin({ + deleteOriginalAssets: true +}); diff --git a/webpack/plugins/index.ts b/webpack/plugins/index.ts index 0692b9f8dd..8771a9bc5f 100644 --- a/webpack/plugins/index.ts +++ b/webpack/plugins/index.ts @@ -1,6 +1,8 @@ +import * as webpack from 'webpack'; const StringReplacePlugin = require('string-replace-webpack-plugin'); import constant from './const'; +import compression from './compression'; const env = process.env.NODE_ENV; const isProduction = env === 'production'; @@ -12,8 +14,10 @@ export default () => { ]; if (isProduction) { - //plugins.push(new webpack.optimize.UglifyJsPlugin()); + plugins.push(new webpack.optimize.UglifyJsPlugin()); } + plugins.push(compression()); + return plugins; };