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