Live data from Hacker News

ES modules: A cartoon deep-dive

hacks.mozilla.org

11–20 of 30 posts

Re: ES modules: A cartoon deep-dive

#12
This is what we get when we encourage rather than actively discourage new innovative ways to explain things. There are so many academic fields that could reduce their learning curve if they only embraced this idea rather than close off any and all attempts to deviate from the path of established rhetoric (which could cause huge cascades of innovation throughout all industries, making many fields look a lot more similar in their pace of growth to the front end world).

Re: ES modules: A cartoon deep-dive

#14
The problem I find with the current ES modules is a lot of statements like this

import {thing} from '../../../thing/in/dir.js'

and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from.

I think babel has something like this using @, but I don't use babel right now.

Re: ES modules: A cartoon deep-dive

#15
post #14

The problem I find with the current ES modules is a lot of statements like this import {thing} from '../../../thing/in/dir.js' and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from. I think babel has something like this using @, but I don't use babel right now.

There are proposals being debated for this. The article mentions specifically this one: https://github.com/domenic/package-name-maps

Re: ES modules: A cartoon deep-dive

#16
post #14

The problem I find with the current ES modules is a lot of statements like this import {thing} from '../../../thing/in/dir.js' and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from. I think babel has something like this using @, but I don't use babel right now.

Moving files around is not something you do all that often. Doing so will present a problem in most any programming language.

Re: ES modules: A cartoon deep-dive

#17
post #14

The problem I find with the current ES modules is a lot of statements like this import {thing} from '../../../thing/in/dir.js' and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from. I think babel has something like this using @, but I don't use babel right now.

Ember has a convention to resolve files in its 'app' directory from your project name, and it makes renaming files a lot easier: `import { thing } from 'my-project/thing/in/dir.js'`

Re: ES modules: A cartoon deep-dive

#18
post #14

The problem I find with the current ES modules is a lot of statements like this import {thing} from '../../../thing/in/dir.js' and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from. I think babel has something like this using @, but I don't use babel right now.

You can set a custom alias, for example nuxt uses ~ for project root. I've seen projects use @ also.

Re: ES modules: A cartoon deep-dive

#19
post #16
post #14

The problem I find with the current ES modules is a lot of statements like this import {thing} from '../../../thing/in/dir.js' and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from. I think babel has something like this using @, but I don't use babel right now.

Moving files around is not something you do all that often. Doing so will present a problem in most any programming language.

This is really not true. Moving files around is trivial in anything with a decent type system and IDE.

Re: ES modules: A cartoon deep-dive

#20

I can't wait for ES module support in Firefox by default (so all major browsers are covered). It feels so good to be able to write code in "plain old JavaScript" again without the need for transpilers and build tools for small apps. I made this minecraft WebGL2 thing ( https://mrspeaker.github.io/webgl2-voxels/ ) all in modules, and being able to just view-source without any shenanigans feels like the old days. The o…

Nice demo!
Post reply on HN