Skip to content

Support import url vanilla ES6 modules. #210

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

Open
brandonkal opened this issue Aug 25, 2019 · 5 comments
Open

Support import url vanilla ES6 modules. #210

brandonkal opened this issue Aug 25, 2019 · 5 comments

Comments

@brandonkal
Copy link

Please describe the feature/suggestion
Currently, modules that use vanilla ES6 imports of a library do not work.

Example:
https://bundlephobia.com/result?p=deqaf
https://github.com/tomhodgins/deqaf/blob/master/index.js

Describe the solution you'd like
It is not clear if there is even a convention for listing these dependencies in a package.json file.
Ideally these could be handled natively when a https import is detected.

Describe any alternatives you've considered
Some options would be to try to parse jsdelivr and unpkg urls to determine the npm package. A better approach would be to just download the file and include the size in the bundle size calculation.

@pastelsky
Copy link
Owner

URL imports aren't supported in node or the browser environments. Why would you use them? Is this for use in deno?

@brandonkal
Copy link
Author

@pastelsky URL import browser support is actually quite high: https://caniuse.com/#search=modules
Node doesn't support ES Modules without flags, so this is for native browser environments. The idea is to get an idea of the size of a dependency that relys on something outside of your bundle.js

@pastelsky
Copy link
Owner

Bundlephobia supports ESM imports that are resolve-able via the filesystem. I was specifically talking about this syntax -

import jsincss from 'https://unpkg.com/jsincss/index.vanilla.js'

Or importing a package via HTTP, which I don't think is valid javascript.

@brandonkal
Copy link
Author

@pastelsky Trust me that is valid Javascript. I understand if it looks foreign if you come from Node. Note that the ECMA module spec is not tied to Node's implementation.
Some info in the V8 engine syntax: https://v8.dev/features/modules#specifiers
You can run in it any modern browser outside of IE 11 inside a <script module>.

As I mentioned in my first post, I am not aware of a convention for specifying these dependencies. Perhaps bundlephobia could support a package.json key:

"nativeDependencies": {
  "https://unpkg.com/jsincss": "jsincss"
}

In this way, even if bundlephobia remains tied to Node's current module resolution, a fallback could be provided with an npm package name.

@pastelsky
Copy link
Owner

Well, TIL. Apologies for pre judgement.

This issue should perhaps be opened with webpack? It probably needs to ignore URLs.

Else if there are resolver plugins / loaders that handle URLs in imports, I'll be happy to add them to bundlephobia

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

No branches or pull requests

2 participants