diff --git a/package-lock.json b/package-lock.json index d173d8c3f..f2086eac2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "y", + "name": "react-chat", "version": "1.0.0", "lockfileVersion": 1, "requires": true, @@ -2503,6 +2503,19 @@ } } }, + "compression-webpack-plugin": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/compression-webpack-plugin/-/compression-webpack-plugin-1.1.12.tgz", + "integrity": "sha512-UpBXSHbrCSdSZieAffqXlAQpLO2fikVVRYibrWlbHYzKpOw1Y4jwkVZ/+S91GzWuJvXSbc8SBy/e8fQJh8uEMQ==", + "dev": true, + "requires": { + "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": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index 86ab28c7c..e8a080cea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/gulpfile.js b/server/gulpfile.js index ad4875957..8850999c9 100644 --- a/server/gulpfile.js +++ b/server/gulpfile.js @@ -7,5 +7,6 @@ gulp.task('start', () => { script: 'index.js', ext: 'js html', env: { NODE_ENV: 'development' } + // env: { NODE_ENV: 'production' } }); }); diff --git a/server/index.js b/server/index.js index 42b8d8152..26e3d0381 100644 --- a/server/index.js +++ b/server/index.js @@ -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'); // 路径管理 @@ -11,6 +12,8 @@ const koa2FallbackApiMiddleware = require('./middlewares/koa2FallbackApiMiddlewa const app = new Koa(); +app.use(compress()); + const server = http.createServer(app.callback()); socketHandle(server); diff --git a/server/package-lock.json b/server/package-lock.json index 3992f187a..a612ad96c 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -638,6 +638,21 @@ "resolved": "http://r.cnpmjs.org/component-inherit/download/component-inherit-0.0.3.tgz", "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=" }, + "compressible": { + "version": "2.0.16", + "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.16.tgz", + "integrity": "sha512-JQfEOdnI7dASwCuSPWIeVYwc/zMsu/+tRhoUvEfXz2gxOA2DNjmG5vhtFdBlhWPPGo+RdT9S3tgc/uH5qgDiiA==", + "requires": { + "mime-db": ">= 1.38.0 < 2" + }, + "dependencies": { + "mime-db": { + "version": "1.38.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz", + "integrity": "sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg==" + } + } + }, "concat-map": { "version": "0.0.1", "resolved": "http://r.cnpmjs.org/concat-map/download/concat-map-0.0.1.tgz", @@ -2760,6 +2775,17 @@ "resolved": "http://r.cnpmjs.org/koa-compose/download/koa-compose-4.0.0.tgz", "integrity": "sha1-KAClE9nDYe8NY4UrA45Pby1adzw=" }, + "koa-compress": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-3.0.0.tgz", + "integrity": "sha512-xol+LkNB1mozKJkB5Kj6nYXbJXhkLkZlXl9BsGBPjujVfZ8MsIXwU4GHRTT7TlSfUcl2DU3JtC+j6wOWcovfuQ==", + "requires": { + "bytes": "^3.0.0", + "compressible": "^2.0.0", + "koa-is-json": "^1.0.0", + "statuses": "^1.0.0" + } + }, "koa-convert": { "version": "1.2.0", "resolved": "http://r.cnpmjs.org/koa-convert/download/koa-convert-1.2.0.tgz", @@ -3497,7 +3523,7 @@ }, "object-assign": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "resolved": "http://r.cnpmjs.org/object-assign/download/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-component": { @@ -4713,7 +4739,7 @@ }, "thenify": { "version": "3.3.0", - "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz", + "resolved": "http://r.cnpmjs.org/thenify/download/thenify-3.3.0.tgz", "integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=", "requires": { "any-promise": "^1.0.0" @@ -4721,7 +4747,7 @@ }, "thenify-all": { "version": "1.6.0", - "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "resolved": "http://r.cnpmjs.org/thenify-all/download/thenify-all-1.6.0.tgz", "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=", "requires": { "thenify": ">= 3.1.0 < 4" diff --git a/server/package.json b/server/package.json index f602d1549..493b952a9 100644 --- a/server/package.json +++ b/server/package.json @@ -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", diff --git a/webpack.config.js b/webpack.config.js index 9db19d2d7..bc38309dc 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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 = { @@ -24,6 +24,7 @@ const publicConfig = { }, plugins: [ new CleanWebpackPlugin(['build/*.*']), + new CompressionPlugin(), new UglifyJSPlugin(), new webpack.DefinePlugin({ 'process.env': {