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

Add support for ES modules in the externals configuration option #8895

Open
philipwalton opened this issue Mar 11, 2019 · 2 comments

Comments

@philipwalton
Copy link
Contributor

commented Mar 11, 2019

Feature request

What is the expected behavior?

Webpack currently supports the concept of externals but it only allows the forms: root, commonjs, commonjs2, and amd.

This is a problem if my source code depends on a third-party library that is hosted on a CDN (in ES module format).

For example, the following does not currently work with webpack:

import {externalLibrary} from 'https://cdn.com/externalLibrary.mjs';

// Do something with `externalLibrary`.
externalLibrary.init();

What is the motivation or use case for adding/changing the behavior?

Now that most browsers natively support loading modules via import statements in module scripts, it should be possible to leverage this feature while still bundling with webpack.

Webpack already has the notion of external dependencies, it should be possible to do the same with external module dependencies.

How should this be implemented in your opinion?

External imports could be placed at the top of each chunk, and their exported variables could be renamed as necessary to ensure no collisions with existing chunk code.

Are you willing to work on this yourself?

I'm willing to help, but cannot commit to full implementation. I looked into whether it would be possible to implement this via a plugin, and it didn't seem like it's currently possible.

@brion-fuller

This comment has been minimized.

Copy link

commented Apr 8, 2019

Any update for this? I would be interested in helping on this task but would like to have an approval beforehand.

@evilebottnawi

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

It is open source, so you can send a PR 👍

@sokra sokra added this to Maybe in webpack 5 May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.