-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (45 loc) · 1.34 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
import chalk from 'chalk'
import http from 'http'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import browserSync from 'browser-sync'
import webpackConfig from './webpack.config'
import app from './src/dev'
import configVars from './config/project.config.js'
const bundler = webpack(webpackConfig)
const server = http.createServer(app)
const port = app.get('port')
// Listen on port 9000 for Express
server.listen(port, () => {
console.log(chalk.green('\n' + '✔ Express Server listening on port'), chalk.cyan(port) + '\n')
})
// Run Browsersync and use middleware for Hot Module Replacement
const bs = browserSync.create()
bs.init({
open: process.argv[2] === '--open' ? true : false,
logFileChanges: true,
host: 'project.local.dev',
proxy: {
target: 'http://localhost:' + port
},
middleware: [
webpackDevMiddleware(bundler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
}
}),
webpackHotMiddleware(bundler)
],
files: [
// put here only files that are not handle by Webpack
configVars.viewsPath + '/**/*.hbs',
configVars.viewsPath + '/**/*.json'
]
})