与RequireJS的冗余依赖项 [英] Redundant dependencies with RequireJS
问题描述
我的问题是让冗余的RequireJS依赖项指向同一个JS库。
My problem is with having redundant RequireJS dependencies that point to the same JS library.
引用的库是 jQuery UI ,它被引用内部和外部库 Gridstack ,这都会导致此问题。
The referenced library is jQuery UI, it's referenced both internally and by external library Gridstack, which is causing this issue.
内部和外部引用都应指向一个文件 jquery-ui.js
。
Both internal and external references should point to ONE file jquery-ui.js
.
如何配置RequireJS(即在 main.js
内)来处理这些引用,而不对任何现有模块进行任何更改/库?
How to configure RequireJS (i.e. inside main.js
) to handle these references as one without doing any changes to any of the existing modules/libraries?
-
JQuery UI v1.11.2 - 我的JQuery UI分发(单个文件)
JQuery UI v1.11.2 - My JQuery UI distribution (single file)
Gridstack 0.2.5-dev - 引用它的库 jquery-ui / core
, jquery-ui / widget
, jquery-ui / mouse
, jquery-ui / draggable
和 jquery-ui / resizable
Gridstack 0.2.5-dev - The library that references it as jquery-ui/core
, jquery-ui/widget
, jquery-ui/mouse
, jquery-ui/draggable
and jquery-ui/resizable
我在内部使用 jquery.ui
推荐答案
虽然路易斯的回答指出我正确的方向,但它仍然带我一些时间找出完整的解决方案,所以我在这里发布我的工作requirejs配置以供将来参考:
While Louis' answer pointed me in the right direction, it still took me some time to figure out the complete solution, so I'm posting my working requirejs config here for future reference:
requirejs.config( {
baseUrl: 'js',
paths: {
jquery: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min',
'jquery.ui': 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min',
lodash: 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min',
gridstack: 'https://cdnjs.cloudflare.com/ajax/libs/gridstack.js/0.3.0/gridstack.min',
'gridstack.jqueryui': 'https://cdnjs.cloudflare.com/ajax/libs/gridstack.js/0.3.0/gridstack.jQueryUI.min',
},
map: {
'*': {
'jquery-ui/data': 'jquery.ui',
'jquery-ui/disable-selection': 'jquery.ui',
'jquery-ui/focusable': 'jquery.ui',
'jquery-ui/form': 'jquery.ui',
'jquery-ui/ie': 'jquery.ui',
'jquery-ui/keycode': 'jquery.ui',
'jquery-ui/labels': 'jquery.ui',
'jquery-ui/jquery-1-7': 'jquery.ui',
'jquery-ui/plugin': 'jquery.ui',
'jquery-ui/safe-active-element': 'jquery.ui',
'jquery-ui/safe-blur': 'jquery.ui',
'jquery-ui/scroll-parent': 'jquery.ui',
'jquery-ui/tabbable': 'jquery.ui',
'jquery-ui/unique-id': 'jquery.ui',
'jquery-ui/version': 'jquery.ui',
'jquery-ui/widget': 'jquery.ui',
'jquery-ui/widgets/mouse': 'jquery.ui',
'jquery-ui/widgets/draggable': 'jquery.ui',
'jquery-ui/widgets/droppable': 'jquery.ui',
'jquery-ui/widgets/resizable': 'jquery.ui',
}
},
} );
require( ['dashhub'] );
请注意,我似乎无法使用 gridstack.all来自cdnjs的.js
脚本。这意味着在您的模块中,您必须在define命令中引用 gridstack
和 gridstack.jqueryui
。
Note that I could not seem to get it working with the gridstack.all.js
script from cdnjs. This means in your modules you must reference both gridstack
and gridstack.jqueryui
in the define command.
这篇关于与RequireJS的冗余依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!