This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.dev.js
78 lines (67 loc) · 1.85 KB
/
index.dev.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Script to start the Server in Development mode.
*/
require('babel-register')
const webpack = require('webpack')
const webpackDev = require('webpack-dev-middleware')
const webpackHot = require('webpack-hot-middleware')
const webpackClient = require('./webpack.config.client.js')
const webpackBase = require('./webpack.config.js')
const mapValues = require('lodash/fp/mapValues')
const http = require('http')
const path = require('path')
const appFactory = require('./server/http').default
const socketio = require('./server/io').default
const data = require('./server/data').default
const PORT = process.env.PORT || 3000
const app = appFactory(data)
const server = http.Server(app)
const config = {
context: path.join(__dirname, 'client'),
entry: mapValues(path => [
'webpack-hot-middleware/client',
'webpack/hot/dev-server',
path
])(webpackClient.entry),
output: {
path: path.join(__dirname, 'public/build'),
publicPath: '/static/build',
filename: '[name].js'
},
resolve: Object.assign({}, webpackBase.resolve),
module: {
rules: [
{ test: /\.js$/, use: ['react-hot-loader/webpack', 'babel-loader'], exclude: /node_modules/ },
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
]
}
const compiler = webpack(config)
const options = {
noInfo: true,
publicPath: config.output.publicPath,
lazy: false,
watchOptions: {
aggregateTimeout: 300
// poll: true,
}
}
app.use(webpackDev(compiler, options))
app.use(webpackHot(compiler))
server.listen(PORT, function () {
console.log('Listening to port ', PORT)
})
socketio(server, data)