-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.js
67 lines (54 loc) · 1.76 KB
/
app.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
62
63
64
65
66
67
"use strict";
var express = require('express');
var app = express();
var fs= require("fs");
app.use(express.static('build'));
app.get('/', function (req, res) {
res.sendfile("build/html/index.html");
});
//指定模板引擎
app.set("view engine", 'ejs');
//指定模板位置
app.set('views', __dirname + '/dev/webpack2/html');
let mainfest = fs.readFileSync(__dirname + '/build/webpack2/manifest.json',"utf-8");
mainfest = JSON.parse(mainfest); //md5 对应表
let moduleMap = fs.readFileSync(__dirname + '/webpackPlugin/build/moduleMap.json',"utf-8");
moduleMap = JSON.parse(moduleMap); //依赖关系 对应表
app.get("/webpack/**", function(req, res) {
var pathName = req.path.replace(/\/webpack\//g,'');
let relyModules = [];//依赖列表
if(moduleMap[pathName+'.js']){
for(var key in moduleMap[pathName+'.js']){
relyModules.push({
name:key,
path:mainfest[key+'.js']
})
}
}
res.render(pathName+'.ejs', {
common : {
name : 'common.js',
path : mainfest['common.js']
},
relyModules : relyModules,
entrance: {
name : pathName + '.js',
path : mainfest[pathName + '.js']
}
});
});
app.get('/combo', function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
var combos = req.param('combo').split(';');
combos=combos || req.param('combo');
var result = '';
for(var i in combos){
result+=fs.readFileSync("build/"+combos[i],"utf-8");
}
res.send(result)
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});