Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not a web dev, but this article has uncovered yet another thing in the js ecosystem that just seems crazy to me.

This makefile snippet:

    lib/index.js: src/index.js
        mkdir -p $(dir $@)
        babel $< --out-file $@ --source-maps
The source and the output are both called index.js? Why, God, WHY???


Because `require` and `import` look at your package's `main`, which (if it's a directory) implies `dirname/index.js`. Building to an `index.js` entry file is, then, the most standard name that allows `require 'modulename'` to work.

The capitalized rending-of-garments is silly. This is transpiling; file names should remain the same from input to output.


Why not? They're both entry points (hence 'index'), both JavaScript (hence '.js') but in different directories. Do you have difficulty distinguishing between /home/me/.vimrc and /home/somebodyelse/.vimrc too?


It's because there is always lag between the latest .js spec and what is supported by browsers. So transpilers (like babel) have to dumb it down from fancyNew.js to somethingIE6MightRun.js

It is not realistic/optimal to try to write your javascript to be supported by all browsers or runtime clients. It's better to write using the latest spec, and just have it dumbed down for you by transpilers at build time

Some more explanation here: https://www.excella.com/insights/typescript-vs-es6-vs-es2015


Because babel compiles javascript to javascript, so you'd expect the input to be a javascript file and the output to be a javascript file.

Of course that sentence contains it's own level of craziness, but the problem does not lie in the build step.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: