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 | 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('未找到组件页面!!!');
|
47 | });
|
48 |
|
49 | app.listen(9000, function (err) {
|
50 | if (err) {
|
51 | console.log(err);
|
52 | return;
|
53 | }
|
54 |
|
55 | console.log('Listening at http://localhost:3006');
|
56 | });
|