-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.dev.js
61 lines (55 loc) · 1.46 KB
/
server.dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
/**
* @File : server.dev.js
* @Author : dtysky (dtysky@outlook.com)
* @Date : 2018-5-10 16:49:53
* @Description:
*/
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.dev.config');
const express = require('express');
const app = new express();
const port = 8888;
const proxyPort = port + 1;
app.use('/assets',
express.static(path.resolve(__dirname, './src/assets'))
);
const devServer = () => {
const server = new WebpackDevServer(webpack(config), {
compress: true,
progress: true,
hot: true,
open: true,
publicPath: config.output.publicPath,
contentBase: path.resolve(__dirname),
disableHostCheck: true,
watchContentBase: true,
watchOptions: {
ignored: /node_modules/
},
https: false,
overlay: true,
historyApiFallback: true,
proxy: [{
context: ['/assets'],
target: `http://localhost:${proxyPort}`
}]
});
server.listen(port, '0.0.0.0', (error) => {
if (error) {
console.log('webpack dev server failed', error);
}
console.info('==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port);
});
}
app.listen(proxyPort, function(error) {
if (error) {
console.error(`Start proxy server error.`);
} else {
console.info('Proxy server for assets is started...');
}
});
devServer();