【发布时间】:2013-07-11 00:52:17
【问题描述】:
我正在使用 requireJS 和 jQuery 的 CDN 版本(现在是推荐的方法)组合一个框架,并且在优化代码时遇到了一些问题。输出是命名空间的,我指定每个模块使用文档中概述的私有版本的 jquery:
require.config({
// Add this map config in addition to any baseUrl or
// paths config you may already have in the project.
map: {
// '*' means all modules will get 'jquery-private'
// for their 'jquery' dependency.
'*': { 'jquery': 'jquery-private' },
// 'jquery-private' wants the real jQuery module
// though. If this line was not here, there would
// be an unresolvable cyclic dependency.
'jquery-private': { 'jquery': 'jquery' }
}
});
// and the 'jquery-private' module, in the
// jquery-private.js file:
define(['jquery'], function (jq) {
return jq.noConflict( true );
});
优化后我看到的问题是“jquery-private.js”文件中未定义“jq”。
有什么想法吗?我试过设置 jq = $ 但这似乎破坏了全局。
谢谢。
【问题讨论】:
-
如果你把地图配置拿走,不尝试使其成为私人版本,它可以正常工作吗?
-
是的,没有地图配置也能正常工作
标签: javascript jquery optimization requirejs