Skip to content

Commit a7c0e5b

Browse files
committed
bug fix
1 parent 2806bf9 commit a7c0e5b

File tree

1 file changed

+15
-52
lines changed

1 file changed

+15
-52
lines changed

lib/page.js

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ _.assign(module.exports.prototype, {
9292
// 生成resourceMap
9393
resourceMap = self.generateSourceMap(analysis);
9494

95-
// 插入resourceMap
95+
// // 插入resourceMap
9696
content = self.injectResourceMap(content, resourceMap);
9797

98-
// process loadUrl
99-
if (conf.autoPack) {
100-
content = self.processLoadUrl(content, analysis.depMap);
101-
}
98+
// // process loadUrl
99+
// if (conf.autoPack) {
100+
// content = self.processLoadUrl(content, analysis.depMap);
101+
// }
102102

103-
if (conf.autoPack) {
104-
content = self.removePlaceholder(content);
105-
content = self.mergeInlineAssets(content);
106-
}
103+
// if (conf.autoPack) {
104+
// content = self.removePlaceholder(content);
105+
// content = self.mergeInlineAssets(content);
106+
// }
107107

108108
file.setContent(content);
109109

@@ -413,7 +413,7 @@ _.assign(module.exports.prototype, {
413413
},
414414
processLoadUrl: function(content, depMap) {
415415
var self = this;
416-
var reg = /require\.loadUrl\s*\(\s*("(?:[^\\"\r\n\f]|\\[\s\S])*"|'(?:[^\\'\n\r\f]|\\[\s\S])*'|\[[\s\S]*?\])\s*,\s*function\(([\s\S]*?)\)\s*{\s*/g;
416+
var reg = /require\.loadUrl\s*\(\s*("(?:[^\\"\r\n\f]|\\[\s\S])*"|'(?:[^\\'\n\r\f]|\\[\s\S])*'|\[[\s\S]*?\])\s*,\s*function\s*\(([\s\S]*?)\)\s*{\s*/g;
417417

418418
content = content.replace(reg, function(m, value, arg) {
419419
var hasBrackets = false;
@@ -423,16 +423,16 @@ _.assign(module.exports.prototype, {
423423
var info;
424424
var ret;
425425

426+
426427
value = value.trim().replace(/(^\[|\]$)/g, function(m, v) {
427428
if (v) hasBrackets = true;
428429
return '';
429430
});
430431
values = value.split(/\s*,\s*/);
431432
args = arg.split(/\s*,\s*/);
433+
432434
for (var i = 0, l = values.length; i < l; ++i) {
433435
info = fis.project.lookup(values[i], self.file);
434-
435-
// console.log('processLoadUrl', info.id, self.ret.map.pkg[info.id + '.min']);
436436
if (!self.ret.map.pkg[info.id + '.min']) {
437437
console.log('[ERROR] there has not the pkg:', info.id);
438438
return m;
@@ -725,11 +725,9 @@ _.assign(module.exports.prototype, {
725725
ret = this.ret,
726726
html,
727727
subpath,
728-
mainScriptFile,
729-
oldUrl, newUrl;
728+
mainScriptFile;
730729

731-
// console.log(conf);
732-
if (conf.outputResourceMapToMainJs) {
730+
if (conf.autoPack && conf.outputResourceMapToMainJs) {
733731
if (!this.mainScriptId) {
734732
this.getMainJs();
735733
}
@@ -738,42 +736,7 @@ _.assign(module.exports.prototype, {
738736
if ((mainScriptFile = this.ret.pkg[subpath])) {
739737
mainScriptFile.setContent('require.resourceMap(' + JSON.stringify(resourceMap, null, this.conf.autoPack ? null : 4) + ')' + LINE_BREAK + mainScriptFile.getContent());
740738
}
741-
742-
// //////////////////// hack fis.file mark ////////////////////////////////////////////
743-
//
744-
// 因为md5固定在了第一次获取的文件内容(详见file.getHash)
745-
// 所以这里出现了死循环:
746-
// 生成resourceMap的时候需要获取打包文件的url,这个时候md5就会固化
747-
// 现在又要把resourceMap放到打包文件里面,内容改变了,但是md5不会变!
748-
// 因此这里需要对md5进行一次hack
749-
// by lqlongli on 2015/11/27
750-
// oldUrl = mainScriptFile.getUrl();
751-
// mainScriptFile.useHash = true;
752-
// newUrl = mainScriptFile.getUrl();
753-
// // console.log('>>>', oldUrl, newUrl);
754-
755-
// // restore 只要使用过这个file.getUrl的地方都需要替换【重要】
756-
// // html文件替换掉url
757-
// this.file.setContent(this.file.getContent().replace(new RegExp(fis.util.escapeReg(oldUrl), 'g'), newUrl));
758-
// // mainScript文件里面替换掉url
759-
// mainScriptFile.setContent(mainScriptFile.getContent().replace(new RegExp(fis.util.escapeReg(oldUrl), 'g'), newUrl));
760-
761-
762-
// oldUrl = mainScriptFile.getUrl();
763-
// mainScriptFile.useHash = true;
764-
// newUrl = mainScriptFile.getUrl();
765-
766-
// // restore 只要使用过这个file.getUrl的地方都需要替换【重要】
767-
// // html文件替换掉url
768-
// content = content.replace(new RegExp(fis.util.escapeReg(oldUrl), 'g'), newUrl);
769-
// // mainScript文件里面替换掉url
770-
// mainScriptFile.setContent(mainScriptFile.getContent().replace(new RegExp(fis.util.escapeReg(oldUrl), 'g'), newUrl));
771-
// // map表替换掉url
772-
// this.ret.map.pkg[this.mainScriptId + '.min'].uri = newUrl;
773-
// //////////////////// hack fis.file mark ////////////////////////////////////////////
774739
}
775-
776-
// console.log(this.file.extras.loadUrls);
777740
(this.file.extras.loadUrls || []).forEach(function(id) {
778741
var subpath = conf.output.replace('${id}', id),
779742
_file = fis.file(fis.project.getProjectPath(), subpath);
@@ -788,7 +751,7 @@ _.assign(module.exports.prototype, {
788751
type: 'js'
789752
};
790753
// 替换md5
791-
file.setContent(file.getContent().replace(new RegExp(fis.util.escapeReg(beforeMd5Url), 'g'), file.getUrl()))
754+
file.setContent(file.getContent().replace(new RegExp(fis.util.escapeReg(beforeMd5Url), 'g'), file.getUrl()));
792755
});
793756
} else {
794757
html = this.modJsCodeGen(resourceMap);

0 commit comments

Comments
 (0)