RequireJS: Set path to 'ignore'

眉间皱痕 提交于 2020-01-11 10:49:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!