Skip to content
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

async injection #36

Open
stefanovualto opened this issue Oct 21, 2019 · 1 comment
Open

async injection #36

stefanovualto opened this issue Oct 21, 2019 · 1 comment

Comments

@stefanovualto
Copy link

Can create an example for the async case?

You can either return the raw content to load, or a Promise which resolves to the content, if you wish to be async.

Because from my understanding the loader needs always to return a string and not a Promise.

My use case is that I would like to inject a third party library that has no npm package but available through a cdn and which is required by my library. I have at the moment a homemade plugin, which injects the text inside the bundle, but I would like to find a cleaner alternative...

Thank you in advance

@adierkens
Copy link
Owner

Loaders can either be sync or async: https://webpack.js.org/api/loaders/#asynchronous-loaders.

In the case where the function passed to webpack-inject-plugin returns a Promise we simply call this.async() on the loader and wire up the callback for you. https://github.com/adierkens/webpack-inject-plugin/blob/master/src/webpack-inject-plugin.loader.ts#L16

I'll add in an example of the async case and a test to go with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants