Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Optimise bundle build and server side add compression #53

Merged
merged 2 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ FROM node:slim
MAINTAINER Vault-UI Contributors

ADD package.json /tmp/package.json
RUN cd /tmp && npm install --silent
RUN mkdir -p /app/ && cp -a /tmp/node_modules /app/
RUN cd /tmp && npm install --silent && mkdir -p /app/ && mv /tmp/node_modules /app/

RUN npm install --silent -g webpack

ADD . /app
WORKDIR /app

RUN webpack && npm run build
RUN npm run build

EXPOSE 8000

CMD ["npm", "run", "serve"]
CMD ["npm", "run", "serve"]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ./server.js --exec babel-node --presets es2015,stage-2",
"build": "babel ./server.js -d . --presets es2015,stage-2",
"build": "webpack --config=webpack.min.config.js",
"serve": "nodemon ./server.js"
},
"repository": {
Expand Down Expand Up @@ -53,6 +53,7 @@
"autoprefixer": "^6.5.3",
"axios": "^0.15.2",
"body-parser": "^1.15.2",
"compression": "^1.6.2",
"copy-to-clipboard": "^3.0.5",
"express": "^4.14.0",
"hbs": "^4.0.1",
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var path = require('path');
var axios = require('axios');
var _ = require('lodash');
var routeHandler = require('./src/routeHandler');
var compression = require('compression');

var PORT = 8000;
var VAULT_URL_DEFAULT = process.env.VAULT_URL_DEFAULT || "";
Expand All @@ -15,7 +16,7 @@ var VAULT_SUPPLIED_TOKEN_HEADER = process.env.VAULT_SUPPLIED_TOKEN_HEADER
var app = express();
app.set('view engine', 'html');
app.engine('html', require('hbs').__express);
app.use('/assets', express.static('dist'));
app.use('/assets', compression(), express.static('dist'));

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
Expand Down
15 changes: 1 addition & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
publicPath: '/assets/',
filename: 'bundle.js'
},
// devtool: 'source-map',
devtool: 'eval',
module: {
loaders: [{
test: /\.jsx?$/,
Expand All @@ -39,19 +39,6 @@ module.exports = {
},
postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
plugins: [
// new webpack.DefinePlugin({
// 'process.env': {
// 'NODE_ENV': JSON.stringify('production')
// }
// }),
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false,
// screw_ie8: true
// },
// comments: false,
// sourceMap: false
// }),
new ExtractTextPlugin("styles.css"),
new webpack.IgnorePlugin(/regenerator|nodent|js-beautify/, /ajv/)
]
Expand Down
23 changes: 23 additions & 0 deletions webpack.min.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var config = require('./webpack.config');
var webpack = require('webpack');

var reactprodmode = new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
});
config.plugins.push(reactprodmode);

var uglify = new webpack.optimize.UglifyJsPlugin({
minimize: true,
comments: false,
sourceMap: false,
compress: {
warnings: false,
}
});
config.plugins.push(uglify);

delete config.devtool;

module.exports = config;