-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
63 lines (45 loc) · 1.37 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
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env babel-node
import path from 'path';
import express from 'express';
import webpack from 'webpack';
import fs from 'fs';
import url from 'url';
import serveIndex from 'serve-index';
import compression from 'compression';
import minimist from 'minimist';
import config from './webpack.config.babel.js';
import history from 'connect-history-api-fallback';
//parse cli arguments
let argv = minimist(process.argv.slice(2));
const app = express();
const compiler = webpack(config);
process.env.NODE_ENV = "development";
//override node environment if --env flag was set to prod
if(argv.prod) process.env.NODE_ENV = "production";
let host = 'localhost';
if(argv.host) host = argv.host;
let port = process.env.PORT || 9000;
if(argv.port) port = argv.port;
app.use(compression());
if(!argv.prod) {
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: false,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
}
//app.use(history());
if(argv.demo) {
app.use('/', express.static('./demos/' + argv.demo));
}else{
app.use('/', express.static('./demos'));
}
app.use('/style.css', express.static('./style.css'));
app.use('/', serveIndex('./demos', {'icons': true}));
app.listen(port, host, (err) => {
if (err) {
console.error(err);
return;
}
console.log(`Listening at http://${host}:${port}`);
});