1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const path = require('path');
|
7 | const express = require('express');
|
8 | const webpack = require('webpack');
|
9 | const config = require('../webpack.config');
|
10 |
|
11 | module.exports = (cherryConfig) => {
|
12 |
|
13 | const sc = cherryConfig.server;
|
14 |
|
15 | const app = express();
|
16 |
|
17 | const compiler = webpack(config);
|
18 |
|
19 | app.use(require('webpack-dev-middleware')(compiler, {
|
20 | noInfo: true,
|
21 | publicPath: config.output.publicPath
|
22 | }));
|
23 |
|
24 | app.use(require('webpack-hot-middleware')(compiler, {
|
25 | reload: false
|
26 | }));
|
27 |
|
28 |
|
29 | if (sc.middleware && sc.middleware.length) {
|
30 | sc.middleware.forEach(item => {
|
31 | app.use(item);
|
32 | });
|
33 | }
|
34 |
|
35 | app.use(express.static('../site'));
|
36 |
|
37 | app.get('*', function (req, res) {
|
38 |
|
39 | res.send('404!!!');
|
40 | });
|
41 |
|
42 |
|
43 | const port = sc.port || 9000;
|
44 | app.listen(port, function (err) {
|
45 | if (err) {
|
46 | console.log(err);
|
47 | return;
|
48 | }
|
49 | console.log(`Listening at http://localhost:${port}`);
|
50 | });
|
51 | }
|