我今天下午一直在尝试使用Grunt和Require JS.我是该text模块的忠实粉丝并使用它来引入我的模板.在非基于Grunt的项目中,我使用了inlineText和stubModulesRequire JS选项来嵌入模板文件,它运行良好.但是,我在与Grunt合作时遇到了麻烦.
需要配置
require.config({
paths: {
// Using Bower for dependency management
text: '../components/requirejs-text/text'
}
});
Run Code Online (Sandbox Code Playgroud)
用法
define(['text!template.html'], function (html) {
// Do stuff with html
});
Run Code Online (Sandbox Code Playgroud)
Gruntfile.js
requirejs: {
dist: {
options: {
baseUrl: 'app/scripts',
optimize: 'none',
preserveLicenseComments: false,
useStrict: true,
wrap: true,
inlineText: true,
stubModules: ['text']
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行后,grunt我在控制台中收到各种错误:
/dist/components/requirejs-text/text.jsLoad timeout for modules: text!template.html_unnormalized2那么两个问题:
text.js代码template.html文件任何想法为什么它不起作用?