-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_browsersync.js
55 lines (46 loc) · 1.61 KB
/
app_browsersync.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
var express = require('express'),
path = require('path'),
consolidate = require('consolidate');
var isDev = process.env.NODE_ENV !== 'production';
var app = express();
var port = 3000;
app.engine('html', consolidate.ejs);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, './server/views'));
app.locals.env = process.env.NODE_ENV || 'dev';
app.locals.reload = false;
if (isDev) {
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackHotMiddleware = require('webpack-hot-middleware'),
webpackDevConfig = require('./webpack.config.js');
var compiler = webpack(webpackDevConfig);
app.use(webpackDevMiddleware(compiler, {
publicPath: webpackDevConfig.output.publicPath,
noInfo: true,
stats: {
colors: true
}
}));
app.use(webpackHotMiddleware(compiler));
require('./server/routes')(app);
// browsersync is a nice choice when modifying only views (with their css & js)
var bs = require('browser-sync').create();
app.listen(port, function(){
bs.init({
open: false,
ui: false,
notify: false,
proxy: 'localhost:3000',
files: ['./server/views/**'],
port: 8080
});
console.log('App (dev) is going to be running on port 8080 (by browsersync).');
});
} else {
app.use(express.static(path.join(__dirname, 'public')));
require('./server/routes')(app);
app.listen(port, function () {
console.log('App (production) is now running on port 3000!');
});
}