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