Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a quick express server to work out hot-reloading pains
- Loading branch information
1 parent
62fa58c
commit 64ab9f2
Showing
10 changed files
with
207 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
], | ||
"verbose": true, | ||
"watch": [ | ||
"server/" | ||
"src/server/", | ||
"src/express-server/" | ||
], | ||
"ext": "js json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
process.env.BABEL_ENV = "server"; | ||
|
||
require('babel-register'); | ||
require('./server'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import express from 'express'; | ||
import morgan from 'morgan'; | ||
|
||
import { renderToString } from 'react-dom/server'; | ||
import { baseReact } from '../crossover/entry'; | ||
|
||
const app = express(); | ||
|
||
app.use(morgan('combined')); | ||
|
||
if (process.env.NODE_ENV === "development") { | ||
console.log("development environment, starting HMR"); | ||
|
||
const webpack = require('webpack'); | ||
const config = require('../../webpack.config.client'); | ||
|
||
const compiler = webpack(config); | ||
|
||
app.use(require('webpack-dev-middleware')(compiler, { | ||
noInfo: true, | ||
publicPath: config.output.publicPath | ||
})); | ||
|
||
app.use(require('webpack-hot-middleware')(compiler)); | ||
} | ||
|
||
app.get('/*', (req, res) => { | ||
const html = renderToString( | ||
baseReact() | ||
); | ||
|
||
res.render('base', { | ||
html, | ||
initialState: { | ||
what: "what", | ||
}, | ||
}); | ||
}); | ||
|
||
app.set('views', './src/server/views'); | ||
app.set('view engine', 'pug'); | ||
|
||
const server = app.listen(3000, () => { | ||
console.log(`App listening at ${server.address().address}:${server.address().port}`); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,73 @@ | ||
const { join } = require('path'); | ||
const webpack = require('webpack'); | ||
|
||
module.exports = (env) => { | ||
console.log("Compiling client code with env set", env); | ||
const prod = process.env.NODE_ENV === "production"; | ||
console.log(`Compiling client code with production set (${prod})`); | ||
|
||
return ({ | ||
entry: !env.prod ? ( | ||
['react-hot-loader/patch', 'webpack-hot-middleware/client', './src/crossover/entry.js'] | ||
) : ( | ||
{ | ||
js: './src/crossover/entry.js', | ||
vendor: ['react', 'react-dom'], | ||
} | ||
), | ||
target: 'web', | ||
output: { | ||
path: join(__dirname, 'dist'), | ||
filename: 'bundle.js', | ||
pathInfo: !env.prod, | ||
publicPath: '/dist/', | ||
}, | ||
devtool: env.prod ? 'source-map' : 'eval', | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.(jsx?)$/, | ||
exclude: /node_modules/, | ||
loaders: [ | ||
'babel-loader', | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: !env.prod ? ([ | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('development'), | ||
BABEL_ENV: JSON.stringify('client'), | ||
}, | ||
}), | ||
]) : ([ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor', | ||
minChunks: Infinity, | ||
filename: 'vendor.bundle.js', | ||
}), | ||
new webpack.LoaderOptionsPlugin({ | ||
minimize: true, | ||
debug: true, | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false, | ||
}, | ||
output: { | ||
comments: false, | ||
}, | ||
sourceMap: false, | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('production'), | ||
BABEL_ENV: JSON.stringify('client-build'), | ||
}, | ||
}), | ||
]), | ||
}); | ||
}; | ||
module.exports = { | ||
entry: !prod ? ( | ||
['webpack-hot-middleware/client', './src/crossover/entry.js'] | ||
) : ( | ||
{ | ||
js: './src/crossover/entry.js', | ||
vendor: ['react', 'react-dom'], | ||
} | ||
), | ||
target: 'web', | ||
output: { | ||
path: join(__dirname, 'dist'), | ||
filename: 'bundle.js', | ||
pathInfo: !prod, | ||
publicPath: '/dist/', | ||
}, | ||
devtool: prod ? 'source-map' : 'eval', | ||
module: { | ||
loaders: [prod ? | ||
{ | ||
test: /\.(jsx?)$/, | ||
exclude: /node_modules/, | ||
loaders: [ | ||
'babel-loader', | ||
], | ||
} : { | ||
test: /\.(jsx?)$/, | ||
loader: 'babel', | ||
exclude: /node_modules/, | ||
include: __dirname, | ||
query: { | ||
presets: ['react-hmre'] | ||
} | ||
}, | ||
], | ||
}, | ||
plugins: !prod ? ([ | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('development'), | ||
BABEL_ENV: JSON.stringify('client'), | ||
}, | ||
}), | ||
]) : ([ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor', | ||
minChunks: Infinity, | ||
filename: 'vendor.bundle.js', | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false, | ||
}, | ||
output: { | ||
comments: false, | ||
}, | ||
sourceMap: false, | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('production'), | ||
BABEL_ENV: JSON.stringify('client-build'), | ||
}, | ||
}), | ||
]), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { join } = require('path'); | ||
const webpack = require('webpack'); | ||
|
||
module.exports = (env) => { | ||
console.log("Compiling client code with env set", env); | ||
|
||
return ({ | ||
entry: !env.prod ? ( | ||
['react-hot-loader/patch', 'webpack-hot-middleware/client', './src/crossover/entry.js'] | ||
) : ( | ||
{ | ||
js: './src/crossover/entry.js', | ||
vendor: ['react', 'react-dom'], | ||
} | ||
), | ||
target: 'web', | ||
output: { | ||
path: join(__dirname, 'dist'), | ||
filename: 'bundle.js', | ||
pathInfo: !env.prod, | ||
publicPath: '/dist/', | ||
}, | ||
devtool: env.prod ? 'source-map' : 'eval', | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.(jsx?)$/, | ||
exclude: /node_modules/, | ||
loaders: [ | ||
'babel-loader', | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: !env.prod ? ([ | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('development'), | ||
BABEL_ENV: JSON.stringify('client'), | ||
}, | ||
}), | ||
]) : ([ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor', | ||
minChunks: Infinity, | ||
filename: 'vendor.bundle.js', | ||
}), | ||
new webpack.LoaderOptionsPlugin({ | ||
minimize: true, | ||
debug: true, | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false, | ||
}, | ||
output: { | ||
comments: false, | ||
}, | ||
sourceMap: false, | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify('production'), | ||
BABEL_ENV: JSON.stringify('client-build'), | ||
}, | ||
}), | ||
]), | ||
}); | ||
}; |