forked from WuTheFWasThat/vimflowy
/
dev_server.js
42 lines (35 loc) · 985 Bytes
/
dev_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
const path = require('path');
const express = require('express');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.dev');
const port = process.env.PORT || 3000;
const server = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
stats: false,
historyApiFallback: true
});
server.app.use(express.static(path.join(__dirname, 'static')));
server.app.get('/:docname', (req, res) => {
res.sendFile(path.join(__dirname, 'static/index.html'));
});
/* eslint-disable no-console */
server.listen(port, 'localhost', err => {
if (err) {
return console.log(err);
}
console.log(`Listening at http://localhost:${port}`);
});
if (process.env.TEST) {
const spawn = require('child_process').spawn;
spawn(
'node_modules/.bin/mocha',
[
'--opts', 'test/mocha.opts',
'--reporter', 'dot',
'--watch',
],
{stdio: 'inherit'}
);
}