-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (46 loc) · 1.46 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require('express');
const path = require('path');
const webpack = require('webpack');
const config = {
devtool: 'source-map',
entry: [
'react-hot-loader/patch',
'webpack-hot-middleware/client',
'./src/index.js'
],
output: {
path: path.join(__dirname, './dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
errorDetails: true,
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
preLoaders: [
{ test: /\.json$/, exclude: /node_modules/, loader: 'json'},
],
loaders: [
{ test: /\.js?/, loader: 'babel?presets[]=es2015,presets[]=stage-0,presets[]=react', exclude: /node_modules/ },
{ test: /\.css$|\.scss$|\.sass$/, loader: 'style!css?modules!sass?sourceMap' },
{ test: /\.jpg$|\.png$/, loader: 'url-loader?limit=10000' }
]
}
}
const app = express()
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.use(express.static('./static'));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, './static/index.html'));
});
app.listen(process.env.PORT || 3000, 'localhost', (err)=> {
if (err) console.log(err)
else console.log('Listening at http://localhost:3000');
})