Compress an assets

This commit is contained in:
syuilo 2017-05-17 00:28:45 +09:00
parent fb70e3b176
commit 4c2a3d8df0
6 changed files with 19 additions and 5 deletions

View file

@ -67,6 +67,7 @@
"@types/websocket": "0.0.33", "@types/websocket": "0.0.33",
"chai": "3.5.0", "chai": "3.5.0",
"chai-http": "3.0.0", "chai-http": "3.0.0",
"compression-webpack-plugin": "0.4.0",
"css-loader": "0.28.1", "css-loader": "0.28.1",
"event-stream": "3.3.4", "event-stream": "3.3.4",
"gulp": "3.9.1", "gulp": "3.9.1",
@ -87,7 +88,7 @@
"stylus-loader": "3.0.1", "stylus-loader": "3.0.1",
"swagger-jsdoc": "1.9.4", "swagger-jsdoc": "1.9.4",
"tslint": "5.2.0", "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" "webpack": "2.5.1"
}, },
"dependencies": { "dependencies": {

View file

@ -2,4 +2,4 @@ extends ../base
block head block head
meta(name='viewport' content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no') 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)

View file

@ -16,7 +16,7 @@ const app = isMobile ? 'mobile' : 'desktop';
// Load app script // Load app script
const script = document.createElement('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('async', 'true');
script.setAttribute('defer', 'true'); script.setAttribute('defer', 'true');
head.appendChild(script); head.appendChild(script);

View file

@ -1,4 +1,4 @@
extends ../base extends ../base
block head block head
script(src=`/assets/dev.${version}.js` async defer) script(src=`/assets/dev.${version}.ja.js.gz` async defer)

View file

@ -0,0 +1,9 @@
/**
* Compressor
*/
const CompressionPlugin = require('compression-webpack-plugin');
export default () => new CompressionPlugin({
deleteOriginalAssets: true
});

View file

@ -1,6 +1,8 @@
import * as webpack from 'webpack';
const StringReplacePlugin = require('string-replace-webpack-plugin'); const StringReplacePlugin = require('string-replace-webpack-plugin');
import constant from './const'; import constant from './const';
import compression from './compression';
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const isProduction = env === 'production'; const isProduction = env === 'production';
@ -12,8 +14,10 @@ export default () => {
]; ];
if (isProduction) { if (isProduction) {
//plugins.push(new webpack.optimize.UglifyJsPlugin()); plugins.push(new webpack.optimize.UglifyJsPlugin());
} }
plugins.push(compression());
return plugins; return plugins;
}; };