Live data from Hacker News

The Makefile I use with JavaScript projects

olioapps.com

11–20 of 525 posts

Re: The Makefile I use with JavaScript projects

#11

    lib/%: src/%
	mkdir -p $(dir $@)
	babel $
Just look at all those magic things. The percent signs! $Well, I know they are not magic ;). But why would I want them when I can actually use normal names like "deps"/"entries" and "target"?

It gets substantially worse as we go down the rabbit whole. Where webpack can easily walk the entire dependency tree by itself, we have to invoke

   src_files := $(shell find src/ -name '*.js')
Where we can use same webpack to seamlessly output the resulting file into an output directory, we need to do the (very unintuitive) pattern substitution:

   transpiled_files := $(patsubst src/%,lib/%,$(src_files))
or even

   flow_files := $(patsubst %.js,%.js.flow,$(transpiled_files))
And when we want to watch for changes? Well, we need an external program anyway.

   $ yarn global add watch
   $ watch make src/
The art of Makefiles is often lost for good reasons: because Makefile don't really cut it anymore.

Re: The Makefile I use with JavaScript projects

#13

Tangential, but I cringe everytime I see the word "transpiler". A compiler is a compiler is a compiler. Previous discussion on this: https://news.ycombinator.com/item?id=15154994

I think it’s useful to distinguish compilation whose target is another language that was originally intended to be human-readable (transpilation) from compilation to a form intended exclusively for machines (compilation to machine code or bytecode).

Re: The Makefile I use with JavaScript projects

#14

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 $ The source and the output are both called index.js? Why, God, WHY???

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?

Re: The Makefile I use with JavaScript projects

#15
As a non-programer the only experience I have with makefiles are unpleasant ones of running ./configure then ./make only to go down an endless rabbit hole of missing dependencies. I am very grateful that yum/apt-get, etc. have come such a long way, they grab all your dependencies, you don't have to wait long periods of time for the code to compile.

I am sure Make still has it's uses, but I am sure glad package managers of have made makefiles irrelevant to me.

Re: The Makefile I use with JavaScript projects

#16

Tangential, but I cringe everytime I see the word "transpiler". A compiler is a compiler is a compiler. Previous discussion on this: https://news.ycombinator.com/item?id=15154994

I think it’s useful to distinguish compilation whose target is another language that was originally intended to be human-readable (transpilation) from compilation to a form intended exclusively for machines (compilation to machine code or bytecode).

> I think it’s useful to distinguish

How and why? And what do you do of compilers which can do either based simply on the backend you select?

Re: The Makefile I use with JavaScript projects

#17
Working somewhere that really embraced Makefiles is actually very nice. If you keep your dependencies simple, the Makefiles to build stuff are pretty simple too, and it works for all the languages you might write software in. You can use it to deploy to servers too.

Re: The Makefile I use with JavaScript projects

#18

Tangential, but I cringe everytime I see the word "transpiler". A compiler is a compiler is a compiler. Previous discussion on this: https://news.ycombinator.com/item?id=15154994

I think it’s useful to distinguish compilation whose target is another language that was originally intended to be human-readable (transpilation) from compilation to a form intended exclusively for machines (compilation to machine code or bytecode).

Compilation is the act of going from one language to another, machine or not. This is what I was taught at least. "Machine code" or "bytecode" holds no special distinction.

In this article's case, there a reasonable exception to made when JavaScript is being "compiled" into JavaScript itself. For that, I don't know what the term is (or if there even is one).

Re: The Makefile I use with JavaScript projects

#20
post #2

One thing I've found useful about gulp and webpack is the fact that it's multiplatform. What is the best approach to make sure your Makefile will work as expected on every platform, meaning, windows included? For example: Can we write file paths using forward-slashes, or is it still an issue? I imagine running it via git bash (bash provided by the git installer on windows).

CMake! No, I'm kidding, don't really use CMake...
Post reply on HN