我的tpl目录结构如下:
-src
-assets
-js
-lib
[files]
-src
-templates
-common
builder_regions.tpl我的require.config是:
require.config({
baseUrl:'src/assets/js',
paths: {
backbone: 'lib/backbone',
jquery: 'lib/jquery.min',
'jquery-ui': 'lib/jquery-ui-1.10.4.custom.min',
underscore: 'lib/underscore.min',
modernizr: 'lib/modernizr.min',
'magnific-popup': 'lib/magnific-popup.min',
text: 'src/assets/jslib/text',
marionette: 'lib/backbone.marionette.min',
tpl: 'lib/underscore-tpl'
},
shim: {
jquery: {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: [ 'jquery', 'underscore' ],
exports: 'Backbone'
},
marionette: {
deps: [ 'jquery', 'underscore', 'backbone' ],
exports: 'Marionette'
},
'jquery-ui': {
deps: [ 'jquery' ],
exports: '$ui'
},
'magnific-popup': {
deps: [ 'jquery' ],
exports: 'magnificPopup'
},
tpl: [ 'text' ]
}
});我的需求模块被设置为:
define([ 'tpl!src/templates/common/builder_regions.tpl', function( Marionette, layoutTpl ) {
console.log( 'did not throw' );
});当我访问模块时,我会得到以下错误:
GET http://localhost:3000/src/assets/js/src/tpl.js 404 (Not Found)为什么当我在tpl.js中提供路径时引用文件require.config?谢谢!
发布于 2014-03-30 00:44:32
如果您的underscore-tpl.js是这一个,那么您不需要为它配置shim,因为它本身调用define。如果您将shim配置用于不需要垫片的东西,那么RequireJS的行为可能会很奇怪。
另一件事与您在这里报告的问题无关,但可能会给您带来麻烦: jQuery至少从1.9版开始就不需要shim了。因此,如果您使用的版本是>= 1.9,您应该删除jquery的shim。
发布于 2014-04-02 12:00:55
试试这个:
define(['marionette', 'tpl!src/templates/common/builder_regions.tpl'], function( Marionette, layoutTpl ) {
console.log( 'did not throw' );
});https://stackoverflow.com/questions/22738423
复制相似问题