Skip to content

Commit c6c68fa

Browse files
author
zhuqiacheng
committed
edit interpolate replace
1 parent 10280c2 commit c6c68fa

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

index.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ module.exports = function(content) {
6565
});
6666
content.reverse();
6767
content = content.join("");
68+
69+
if(config.interpolate){
70+
var reg = /\$\{require\([^)]*\)\}/g;
71+
var result;
72+
var reqList = [];
73+
while(result = reg.exec(content)){
74+
reqList.push({
75+
length : result[0].length,
76+
start : result.index,
77+
value : result[0]
78+
})
79+
}
80+
reqList.reverse();
81+
content = [content];
82+
reqList.forEach(function(link) {
83+
var x = content.pop();
84+
do {
85+
var ident = randomIdent();
86+
} while(data[ident]);
87+
data[ident] = link.value.substring(11,link.length - 3)
88+
content.push(x.substr(link.start + link.length));
89+
content.push(ident);
90+
content.push(x.substr(0, link.start));
91+
});
92+
content.reverse();
93+
content = content.join("");
94+
}
95+
6896
if(typeof config.minimize === "boolean" ? config.minimize : this.minimize) {
6997
var minimizeOptions = assign({}, config);
7098

@@ -89,15 +117,12 @@ module.exports = function(content) {
89117

90118
content = htmlMinifier.minify(content, minimizeOptions);
91119
}
120+
121+
content = JSON.stringify(content);
92122

93-
if(config.interpolate) {
94-
content = compile('`' + content + '`').code;
95-
} else {
96-
content = JSON.stringify(content);
97-
}
98-
99-
return "module.exports = " + content.replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) {
123+
return "module.exports = " + content.replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) {
100124
if(!data[match]) return match;
101125
return '" + require(' + JSON.stringify(loaderUtils.urlToRequest(data[match], root)) + ') + "';
102126
}) + ";";
127+
103128
}

0 commit comments

Comments
 (0)