This repository was archived by the owner on Jul 19, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
lessons/11-productionish-server Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 44 "description" : " " ,
55 "main" : " index.js" ,
66 "scripts" : {
7- "start" : " webpack-dev-server --inline --content-base . --history-api-fallback"
7+ "start" : " if-env NODE_ENV=production && npm start:prod || npm run start:dev" ,
8+ "start:dev" : " webpack-dev-server --inline --content-base . --history-api-fallback" ,
9+ "start:prod" : " webpack && node server.js"
810 },
911 "author" : " " ,
1012 "license" : " ISC" ,
1113 "dependencies" : {
14+ "compression" : " ^1.6.2" ,
15+ "express" : " ^4.14.0" ,
16+ "if-env" : " ^1.0.0" ,
1217 "react" : " ^0.14.7" ,
1318 "react-dom" : " ^0.14.7" ,
1419 "react-router" : " ^2.0.0"
Original file line number Diff line number Diff line change 1+ var express = require ( "express" ) ;
2+ var path = require ( "path" ) ;
3+ var compression = require ( 'compression' ) ;
4+
5+ var app = express ( ) ;
6+ // serve our static stuff like index.css
7+ app . use ( express . static ( __dirname ) ) ;
8+ app . use ( compression ( ) ) ;
9+
10+ // send all requests to index.html so browserHistory in React Router works
11+ app . get ( "*" , function ( req , res ) {
12+ res . sendFile ( path . join ( __dirname , "index.html" ) )
13+ } ) ;
14+
15+ var PORT = process . env . PORT || 8080 ;
16+ app . listen ( PORT , function ( ) {
17+ console . log ( 'Production Express server running at localhost:' + PORT ) ;
18+ } ) ;
Original file line number Diff line number Diff line change 1+ var webpack = require ( 'webpack' ) ;
2+
13module . exports = {
24 entry : './index.js' ,
35
46 output : {
7+ path : 'public' ,
58 filename : 'bundle.js' ,
69 publicPath : '/'
710 } ,
@@ -10,5 +13,12 @@ module.exports = {
1013 loaders : [
1114 { test : / \. j s $ / , exclude : / n o d e _ m o d u l e s / , loader : 'babel-loader?presets[]=es2015&presets[]=react' }
1215 ]
13- }
16+ } ,
17+ // add this handful of plugins that optimize the build
18+ // when we're in production
19+ plugins : process . env . NODE_ENV === 'production' ? [
20+ new webpack . optimize . DedupePlugin ( ) ,
21+ new webpack . optimize . OccurrenceOrderPlugin ( ) ,
22+ new webpack . optimize . UglifyJsPlugin ( )
23+ ] : [ ] ,
1424}
You can’t perform that action at this time.
0 commit comments