1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const path = require('path');
|
7 | const express = require('express');
|
8 | const mockMiddleware = require('@nfe/mock-middleware');
|
9 | const webpack = require('webpack');
|
10 |
|
11 | const config = require('./webpack.config');
|
12 |
|
13 |
|
14 | const app = express();
|
15 | const compiler = webpack(config);
|
16 |
|
17 | app.use(require('webpack-dev-middleware')(compiler, {
|
18 | noInfo: true,
|
19 | publicPath: config.output.publicPath
|
20 | }));
|
21 |
|
22 | app.use(require('webpack-hot-middleware')(compiler));
|
23 |
|
24 | app.use(express.static('site'));
|
25 |
|
26 |
|
27 | const isRemote = process.env.SCENE === 'remote';
|
28 |
|
29 | let mapConfig = {
|
30 | map: 'mock/local.js',
|
31 | delay: 300
|
32 | };
|
33 |
|
34 | if (isRemote) {
|
35 | mapConfig = {
|
36 | map: 'mock/remote.js',
|
37 | delay: 0
|
38 | };
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | app.get('*', function (req, res) {
|
45 |
|
46 | res.send('404!!!');
|
47 | });
|
48 |
|
49 | const port = 9000;
|
50 |
|
51 | app.listen(port, function (err) {
|
52 | if (err) {
|
53 | console.log(err);
|
54 | return;
|
55 | }
|
56 |
|
57 | console.log(`Listening at http://localhost:${port}`);
|
58 | });
|