Skip to content

Allow globally loaded javascript libs #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
filipesilva opened this issue Aug 16, 2016 · 7 comments · Fixed by #1747
Closed

Allow globally loaded javascript libs #1717

filipesilva opened this issue Aug 16, 2016 · 7 comments · Fixed by #1747
Assignees
Labels
feature Issue that requests a new feature P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful

Comments

@filipesilva
Copy link
Contributor

Some javascript libraries need to be loaded on the global scope, especially older ones. A great, common example is bootstrap, which needs jquery to be globally available.

Different build systems have different ways to allow this. Webpack has several alternatives to shimming modules, and so does SystemJS.

Angular-CLI needs to provide a way to load these files in order to provide interop with the simplest way of loading javascript files.

@filipesilva filipesilva added feature Issue that requests a new feature P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful feature: webpack labels Aug 16, 2016
@filipesilva filipesilva self-assigned this Aug 16, 2016
@iamyojimbo
Copy link

iamyojimbo commented Aug 16, 2016

In case anyone really needs this NOW, in Webpack, the solution is to do:

window['jQuery'] = require('jquery')
window['Chart'] = require('chart.js')

I do this in my main.ts file because I assumed this needs to be done before the dependencies are loaded (as some of them have checks to see if jQuery is there before you even call a function).

I don't know if this works with SystemJS too.

@filipesilva
Copy link
Contributor Author

@iamyojimbo very good advice, thank you!

@filipesilva
Copy link
Contributor Author

#1747 adds instructions on how to use libs that need global scope using @iamyojimbo's technique.

It should be enough for now but if people start having more problems with libs, we can add more functionality to address global scripts.

@filipesilva
Copy link
Contributor Author

We looked into it a bit more and decided to take another approach to the global libs issue. We decided to provide a config item to specify javascript files that should be loaded outside of the module ecosystem, as if they were in a script tag.

We feel this should make it easier for people to add libs since they won't have to poke around for the exports, and also make it more compatible with all kinds of libs.

@iamyojimbo
Copy link

@filipesilva by, "poke around the the exports", what do you mean exactly?

@filipesilva
Copy link
Contributor Author

Using your method, you need to know the exact names of the needed exports. For jquery this is jQuery and $. These are well known enough but for many libraries that isn't so clear, so a user would have to look into the source to figure out what exports they should put in window.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Issue that requests a new feature P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants