RequireJS: Set path to ignore

2024/2/27 8:29:48

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.

Answer

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.

http://en.ppmy.cn/q/42260.html

Related Q&A

Javascript template system - PURE, EJS, jquery plugin?

has anybody used a javascript template system? I used to use the one that is embedded with JavascriptMVC but i now doing server side development so i wanted a more streamlined/thinner version..I have …

RegEx to remove all styles but leave color and background-color if they exist

I am still not able to use regular expressions by heart, thus could not find a final solution to strip out all styles from <p style="">...</p> using RegEx with Javascript, but lea…

Pass props nicely to screens in react navigation

I want to pass a prop to the screen. When I try that inline e.g (props) => <Comp {...props} {...customProps} /> I get a warning message, that I shouldnt parse functions to that component prope…

How do I check if message content includes any items in an array?

Im making a discord bot and Im trying to make a forbidden words list using arrays. I cant seem to find out how to make this work. Heres my current code:if (forbidenWords.includes(message.content)) {mes…

.js file works in chrome and firefox but not IE

When testing my website out in IE11 certain parts of it dont work and I believe the issue lies with my custom.js file as all the problems link to that js. However, the page works perfectly in Chrome …

scrollTo not working in Safari

I have this scrollable list<ol><li>...</li>... </ol>DEMONow, I can scroll programatically using document.querySelector(ol).scrollTo(100);But this doesnt work in Safari. Although…

Javascript: Hijack Copy?

I was just reading the Times online and I wanted to copy a bit of text from the article and IM it to a friend, but I noticed when I did so, it automatically appended the link back to the article in wha…

Prevent google overlay/infowindow from allowing clicks through to markers underneath

Im trying to make some custom Google maps info windows, but Im getting the issue where markers underneath my custom info window is clickable through the info window.Heres an example (basically straight…

Remove empty space when visible property is set to false using JavaScript

Im having a DropdownList and when its Selected Value is changed (for ex: 0 ) I need to set the visible property of a Panel to True and the visible property of another Panel to False.and when another Va…

Can JavaScript or jQuery sort a JSON array on multiple criteria?

I have a JSON array of potential results for an autocomplete list. The list is defined as:var fundList = [ //theres lots more than this{ "name": "Pension Managed Fund 1" },{ "n…