whatwg / loader

Loader Standard
https://whatwg.github.io/loader/
Creative Commons Zero v1.0 Universal
609 stars 45 forks source link

Relative module URLs starting without "./" #131

Closed bangseongbeom closed 8 years ago

bangseongbeom commented 8 years ago

I agree that the name resolution policy may not follow the URL syntax fully, but it may confuse the users if it's invalid to start without "./" because <link> in HTML and @import in CSS permit both with and without.

caridy commented 8 years ago

<script type="module" src="path/to/something.js"></script> works just fine to match traditional <link> and <script> tags, and it is specified here: https://html.spec.whatwg.org/#resolve-a-module-specifier

As for the import statements, you should be able to do import foo from "foo"; but it will require you to define a custom @@resolve hook that understands what "foo" means, because the default behavior of the loader will not know what to do with it. In the other hand, other environments, like node, will have a default behavior for it, which relies on npm.

domenic commented 8 years ago

and it is specified here: https://html.spec.whatwg.org/#resolve-a-module-specifier

Not quite, that specifies how import is processed. I believe you're looking for https://html.spec.whatwg.org/#prepare-a-script step 16.4.

caridy commented 8 years ago

:+1: