AMD (require.js)如何在一个非AMD js文件中处理多个类?
How does AMD (require.js) handle multiple classes in a single non-amd js file?
我使用了一堆来自MootoolsMore库的组件,它们都被编译成一个单一的.js文件。是否有一种方法来定义库一次在shim和访问所有类在它?下面的方法不起作用,但是我该怎么做呢?
shim:{
mootoolsMore:{
deps : ["mootools"]
exports : ["Slider", "Sortables"]
}
}
// then inside my module I could access the Slider component like so
define( function(require) {
var Slider = require('mootoolsMore').Slider
不需要只针对RequireJS的"shim"功能。你可以使用标准的AMD加载器API:
require(['js!path/to/MooToolsCore.js'], function(){
// nesting in order to insure that Moo Core runs first
require(['js!path/to/MooToolsMore.js'], function(){
// Your Slider and Sortables will be in global.
// just use them.
window.Slider(/* ... */)
})
})
注意,RequireJS不需要显式地声明"js!"插件,相反,它只需要查看文件的扩展名。如果它是"。js",它通过"js"插件运行文件。这是非标准的行为(在AMD规范中没有),但在RequireJS中,你应该能够替换这样的行:
['js!path/to/MooToolsMore.js']
与这个:['path/to/MooToolsMore.js']
相关文章:
- 无法加载Ace.js编辑器模式和主题(命名空间项目&AMD require.js&grunt
- 为Backbone.js源文件(amd-app.js)重新创建构建环境
- 如何将预编译的hogan.js模板封装到AMD模块中
- 为AMD、CommonJS等打包js库
- 如何从TypeScript编译中现有的AMD js类继承到AMD模块
- 在Symfony2项目中可以使用require.js和异步模块定义(AMD)
- 拖放区 AMD 需要 JS 问题
- 配置需要 js 才能在 javascript 中加载 AMD 模块
- 要求.js,AMD和使用jwPlayer 7的“缺少许可证密钥”
- 未捕获错误:按 require.js 加载非 AMD 脚本时没有定义调用
- 如何使用jspm/system.js正确加载本地AMD模块
- Davis.js作为AMD模块
- Dropzone.js AMD内部Backbone视图事件
- 在设计JS库时,我应该让它与RequireJS/AMD兼容还是不兼容
- 使用ScrollMagic.js作为AMD模块
- 为什么Underscore.js删除了对AMD的支持
- 在没有r.js的情况下连接和缩小AMD模块
- 在新的typescript文件(0.9)中使用现有的AMD js模块
- 不能在registerSuite .js中要求AMD模块
- AMD (require.js)如何在一个非AMD js文件中处理多个类?