Skip to content

Commit

Permalink
performance: trigger gzip => add compression webpack plugin and koa-c…
Browse files Browse the repository at this point in the history
…ompress
  • Loading branch information
aermin committed Feb 24, 2019
1 parent d701d48 commit 4c5da83
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"babel-preset-stage-0": "^6.24.1",
"bundle-loader": "^0.5.6",
"clean-webpack-plugin": "^0.1.19",
"compression-webpack-plugin": "v1.1.12",
"css-loader": "^0.28.11",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
Expand Down
1 change: 1 addition & 0 deletions server/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gulp.task('start', () => {
script: 'index.js',
ext: 'js html',
env: { NODE_ENV: 'development' }
// env: { NODE_ENV: 'production' }
});
});
3 changes: 3 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const cors = require('koa2-cors');
const compress = require('koa-compress');
const http = require('http');
const statics = require('koa-static'); // 静态资源服务插件
const path = require('path'); // 路径管理
Expand All @@ -11,6 +12,8 @@ const koa2FallbackApiMiddleware = require('./middlewares/koa2FallbackApiMiddlewa

const app = new Koa();

app.use(compress());

const server = http.createServer(app.callback());
socketHandle(server);

Expand Down
32 changes: 29 additions & 3 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jsonwebtoken": "^8.1.0",
"koa": "^2.3.0",
"koa-bodyparser": "^4.2.0",
"koa-compress": "^3.0.0",
"koa-cors": "0.0.16",
"koa-router": "^7.2.1",
"koa-static": "^4.0.3",
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const CompressionPlugin = require('compression-webpack-plugin');
const commonConfig = require('./webpack.common.config.js');

const publicConfig = {
Expand All @@ -24,6 +24,7 @@ const publicConfig = {
},
plugins: [
new CleanWebpackPlugin(['build/*.*']),
new CompressionPlugin(),
new UglifyJSPlugin(),
new webpack.DefinePlugin({
'process.env': {
Expand Down

0 comments on commit 4c5da83

Please sign in to comment.