RequireJS:设置'忽略'的路径 [英] RequireJS: Set path to 'ignore'
问题描述
我正在使用第三方库(通过bower)声明我不想要的依赖项(它只是样式)。是否可以将该依赖项设置为忽略或某些此类值?
I'm using a third-party library (through bower) that declares a dependency that I do not want (it's just styling). Is it possible to set that dependency to 'ignore,' or some such value?
例如:
define(['jquery','dep_i_dont_want'], function(){...});
在require config中:
In require config:
paths: {
'jquery': 'path/to/jquery',
'dep_i_dont_want': 'ignore'
}
我只需要查找'dep_i_dont_want',看看它被忽略了,继续前进而不包含它或失败。这可能吗?我不想编辑第三方JS文件。
I would just require to look up 'dep_i_dont_want', see that it is ignored, and move on without including it or failing. Is this possible? I do not want to edit the third-party JS file.
对于上下文,似乎在'paths'对象中不可能这样:没有未定义,null,'','忽略','空白'等似乎都有效。
For context, it doesn't seem that this is possible in the 'paths' object: none of undefined, null, '', 'ignore', 'blank', etc. seem to work.
我想我可以把它指向一个虚拟模块,但感觉喜欢作弊。
I suppose I could just point it to a dummy module, but that feels like cheating.
推荐答案
我想我可以把它指向一个虚拟模块,但感觉喜欢作弊。
I suppose I could just point it to a dummy module, but that feels like cheating.
是的,这就是你要做的。没有办法告诉RequireJS忽略这个模块。 (对于从CDN加载的模块,您可以为 r.js
提供 empty:
方案,但这仅适用于 r.js
'在优化期间使用。)
Yes, this is what you have to do. There is no way to tell RequireJS "ignore this module". (There's the empty:
scheme that you can give to r.js
for modules loaded from CDNs but that's just for r.js
' use during optimization.)
您可以做什么而不是设置某种空路径在您调用 require.config
之前添加此模块:
What you can do rather than setting a path to some sort of empty module is add this before your call to require.config
:
define('dep_i_dont_want');
这将以这样的方式定义模块:如果在某处需要它,其值将为 undefined
。
This will define the module in such a way that if it is required somewhere, its value will be undefined
.
这篇关于RequireJS:设置'忽略'的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!