这是我的配置
requirejs.config({
baseUrl : 'vassets/lib/',
shim : {
'knockout' : [ 'jquery' ]
},
paths : {
jquery : 'jquery/jquery.min',
knockout : 'knockout/knockout',
selectize : 'selectize.js/js/standalone/selectize.min',
main : '/vassets/js/koapp/main',
jsep : '/vassets/js/jsep/jsep.min'
}
});
jsep是这里提供的javascript表达式解析器http://jsep.from.so/
这是我的模块定义:
define ()->
require ['jsep'],(jsep)->
console.log jsep
# does not work, jsep is undefined
()->
console.log jsep
# does not work, jsep is available. but HOW????
# I dont see this type of usage in api documnentation. How does this work?
此外,以下模块定义也不起作用
define ['jsep'], (jsep)->
console.log jsep
# does not work
# this is the normal usage I find in documentation, why this does not work???
可以
答案 0 :(得分:1)
添加垫片,解决了问题。对于未实现define函数的模块,如require js所要求的。在shim配置中需要导出配置。以下配置使其有效。
requirejs.config({
baseUrl : 'vassets/lib/',
shim : {
'knockout' : [ 'jquery' ],
'jsep': {
exports: 'jsep'
}
},
paths : {
jquery : 'jquery/jquery.min',
knockout : 'knockout/knockout',
selectize : 'selectize.js/js/standalone/selectize.min',
main : '/vassets/js/koapp/main',
jsep : '/vassets/js/jsep/jsep.min'
}
});