Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 7f33684

Browse files
committed
Lesson 11 Final
1 parent 7810c00 commit 7f33684

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
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 run start:prod || npm run start:dev",
8+
"start:dev": "webpack-dev-server --inline --content-base public/ --history-api-fallback",
9+
"start:prod": "webpack && node server.js"
810
},
911
"author": "",
1012
"license": "ISC",
1113
"dependencies": {
14+
"compression": "^1.6.1",
15+
"if-env": "^1.0.0",
1216
"react": "^0.14.7",
1317
"react-dom": "^0.14.7",
1418
"react-router": "^2.0.0"
File renamed without changes.
File renamed without changes.

server.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var express = require('express')
2+
var path = require('path')
3+
var compression = require('compression')
4+
5+
var app = express()
6+
7+
app.use(compression())
8+
9+
// serve our static stuff like index.css
10+
app.use(express.static(path.join(__dirname, 'public')))
11+
12+
// send all requests to index.html so browserHistory works
13+
app.get('*', function (req, res) {
14+
res.sendFile(path.join(__dirname, 'public', 'index.html'))
15+
})
16+
17+
var PORT = process.env.PORT || 8080
18+
app.listen(PORT, function() {
19+
console.log('Production Express server running at localhost:' + PORT)
20+
})
21+

webpack.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
var webpack = require('webpack')
2+
13
module.exports = {
24
entry: './index.js',
35

46
output: {
7+
path: 'public',
58
filename: 'bundle.js',
69
publicPath: '/'
710
},
811

12+
plugins: process.env.NODE_ENV === 'production' ? [
13+
new webpack.optimize.DedupePlugin(),
14+
new webpack.optimize.OccurrenceOrderPlugin(),
15+
new webpack.optimize.UglifyJsPlugin()
16+
] : [],
17+
918
module: {
1019
loaders: [
1120
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' }

0 commit comments

Comments
 (0)