-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (38 loc) · 1.11 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
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var fs = require('fs');
var path = require('path');
var express = require('express');
var openurl = require('openurl');
var webpackDevConfig = require('./webpack.dev.config');
var config = require('./shark-deploy-conf.json');
var compiler = webpack(webpackDevConfig);
var app = express();
app.use(webpackDevMiddleware(compiler, {
publicPath: webpackDevConfig.output.publicPath,
stats: {
colors: true,
chunks: false
},
watchOptions: {
poll: true
}
}));
app.use(webpackHotMiddleware(compiler));
//font
app.use('/font', express.static(path.join(__dirname, 'font')));
//ajax mock
app.use('/xhr', function (req, res) {
var data = path.join(__dirname, 'test/mock/xhr', req.path);
if (fs.existsSync(data)) {
res.send(fs.readFileSync(data));
} else {
res.status(404).send('file not exist !');
}
});
app.listen(9000, function () {
if (config.openurl) {
openurl.open(config.openurl);
}
});