-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1.17 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
import express from 'express';
import path from 'path';
let app = express();
/*** Webpack imports ***/
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import config from './webpack.config.js';
const webpackOptions = {
publicPath: config.output.publicPath,
// needed so that when going to the localhost:3000 it will load the contents
// from this directory
contentBase: config.devServer.contentBase,
hot: true,
quiet: false,
// hides all the bundling file names
noInfo: true,
// adds color to the terminal
stats: {
colors: true
}
};
const isDevelopment = process.env.NODE_ENV !== 'production';
const port = isDevelopment ? 3000 : process.env.PORT;
const public_path = path.join(__dirname, 'public');
app.use('/', express.static(public_path));
/*** during development I am using a webpack-dev-server ***/
if(isDevelopment) {
new WebpackDevServer(webpack(config), webpackOptions)
.listen(port, 'localhost', function(err) {
if (err) { console.log(err); }
console.log(`Listening on port: ${port}`);
});
}
// use es5 syntax so heroku works.
module.exports = app;