使用requeire导入HTML模板的时候,出现一个奇怪的问题:
代码如下:
代码:
define(function(require, exports, module) {
var $ = require('$'),template=require('template'),html=require('../../html/test.tpl'),json=require('../../html/data.json');
$('body').append(template.compile(html)(json));
console.log(1);
});
以上代码可以正常运行。其中template为一个依赖的template库.
当通过GRUNT编译后代码:
define("app1/test", ["jquery/jquery/1.10.1/jquery", "artTemplate/template", "../../html/data.json"], function (a) {
var b = a("jquery/jquery/1.10.1/jquery"), c = a("artTemplate/template"), d = a("../../html/test.tpl"), e = a("../../html/data.json");
b("body").append(c.compile(d)(e)), console.log(1)
});
编译后代码,除了后缀为.tpl的代码都自动加上了依赖,并且由于没有加入依赖,
造成:
d = a("../../html/test.tpl") 返回为NULL
另经过我测试,只要在define()中指定了[],如果有任何依赖没有写入,都无法起效
不明所以,请大神指教
PS:使用的seajs-text来加载HTML,并且使用的preload来加载