-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (35 loc) · 1.44 KB
/
server.js
File metadata and controls
54 lines (35 loc) · 1.44 KB
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
let path = require('path');//test release
let http = require('http');
let express = require('express');
let tempSrc=[];
let app = express();
app.use('/src',express.static(path.resolve(__dirname,'./src/')));
// ************************************
// This is the real meat of the example
// ************************************
(function () {
// Step 1: Create & configure a webpack compiler
let webpack = require('webpack');
let webpackConfig = require(process.env.WEBPACK_CONFIG ? process.env.WEBPACK_CONFIG : './webpack.config');
let compiler = webpack(webpackConfig);
//let router=express.Router();
// Step 2: Attach the dev middleware to the compiler & the server
app.use(require("webpack-dev-middleware")(compiler, {
noInfo: true, publicPath: webpackConfig.output.publicPath
}));
// Step 3: Attach the hot middleware to the compiler & the server
app.use(require("webpack-hot-middleware")(compiler, {
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000, reload: true
}));
})();
// Do anything you like with the rest of your express application.
app.get("/", function (req, res) {
res.sendFile(__dirname + '/demo.html');
});
/*------------------测试接口------------------*/
if (require.main === module) {
let server = http.createServer(app);
server.listen(process.env.PORT || 3030, function () {
console.log("Listening on %j", server.address());
});
}