问题
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?
e.g.:
define(['jquery','dep_i_dont_want'], function(){...});
In require config:
paths: {
'jquery': 'path/to/jquery',
'dep_i_dont_want': 'ignore'
}
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.
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.
回答1:
I suppose I could just point it to a dummy module, but that feels like cheating.
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.)
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');
This will define the module in such a way that if it is required somewhere, its value will be undefined
.
来源:https://stackoverflow.com/questions/31526609/requirejs-set-path-to-ignore