Live data from Hacker News

Writing JavaScript without a build system

jvns.ca

21–30 of 187 posts

Re: Writing JavaScript without a build system

#21

I've used `tsc --watch` as an almost-no-build-step way to write plain TypeScript with better structure (separate files, etc) for projects where dependencies aren't necessary, which works reasonably well with a few quirks, but I wish there were something more purpose-built for the task. TypeScript running natively in the browser would be amazing but I doubt that'll ever happen.

The problem with build systems isn't the existence of a build step but the necessity of the build system and its configuration.

Typescript is baffling-ly complex to use compared to something like python.

Re: Writing JavaScript without a build system

#22
post #5

Use npm to install libraries one time only. Try to use as few dependencies as possible. You don't need a framework--components are achievable without vue and react etc. Server side rendering and VDom are really not needed for most projects. Think of Programming in JavaScript, CSS and F5 rather than Typescript and SASS as the equivalent of Marcus Aurelius' Stoicism.

JavaScript and CSS are to Stoicism as Typescript and SASS are to _____?

Epicureanism?

Re: Writing JavaScript without a build system

#23
> But my experience with build systems (not just Javascript build systems!), is that if you have a 5-year-old site, often it’s a huge pain to get the site built again.

5 years? More like 5 minutes in my experience. I probably spend 50% of my time trying to figure out why the build system is breaking, again.

Re: Writing JavaScript without a build system

#24

Earlier quoted context omitted.

Huh… in Python I feel like the tooling is largely missing.

While the Python ecosystem trends towards a similar state as the JS ecosystem, at least no one yet needs to have any ideas about "tree shaking" and hype that as some kind of "new idea". When one needs to "shake out" code, because it has become too much, one should really think about not getting that code in there in the first place. In the Python ecosystem some of the tooling does not exist, because it is not needed.…

> Hopefully people keep dependencies of projects to a minimum

This is not my experience of Python. Some of the tools I’ve installed via Homebrew have whole forests of dependencies. And don’t get me started on all the different Python versions they require.

Re: Writing JavaScript without a build system

#25
post #10

> I’d love more tips for no-build-system javascript 1. MDN has a comprehensive guide on JavaScript modules [0] 2. A build system free way to build interactive websites could be to combine libraries like htmx[1] and or lit[2] or just the sub package lit-html[3]. Or just go with native web components and a bit of AJAX. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid... [1] https://github.com/bigskysoft…

+1 for Lit. It seems like they're mostly recommending that you use TypeScript and a build system, but you can 100% still just pull the library from a CDN with native JS modules [0].

It leans into a lot of the web components spec so the library is pretty small, and the templating system is just ES6 tagged template literals parsed by the browser's DOM parser and any embedded variables are updated dynamically [1].

[0] https://lit.dev/docs/getting-started/#use-bundles

[1] https://lit.dev/docs/templates/overview/

Re: Writing JavaScript without a build system

#26

> But my experience with build systems (not just Javascript build systems!), is that if you have a 5-year-old site, often it’s a huge pain to get the site built again. 5 years? More like 5 minutes in my experience. I probably spend 50% of my time trying to figure out why the build system is breaking, again.

If you put it in docker there's basically a decade guarantee

Re: Writing JavaScript without a build system

#27
One of my favourite hacks I did recently was in 2020 when soup.io was unexpectedly discontinued with short notice; to promote my scraping framework, Skyscraper, I quickly whipped up a content downloader. It produced an archive of assets, and I also added a rudimentary browser.

The beauty of it was that it was a single static HTML file, copied verbatim to the archive. The only moving part, apart from the actual images/posts/videos, was a file called soup.js, which was just `window.soup=` plus the content metadata as JSON.

I didn’t even bother to have a separate JS file for the actual code, much less a build system. I put the JS right into a `` tag in the HTML. I used ES modules, HyperApp as a minimalistic React/Redux workalike, and mini.css for some sane default styling.

I was amazed at how far I could get with such a rudimentary tooling. 117 SLOCs of HTML+JS, working equally well served from a server and from a local filesystem, complete with pagination, permalinks, and a jump-to-page dialog.

Here it is in action, serving a friend’s soup archive: https://soup.tomash.eu/archive (warning: some content can be touchy and/or NSFW). View source for a glimpse of how it works.

Re: Writing JavaScript without a build system

#29
A lightning rod of an idea I’m sure, but would it help if typescript was accepted by browsers but ignored? Then I can write my typings in-line rather than in comments, and check them, but not have to transpile.

I guess “enum” as a special snowflake would fail this.

Where I’m coming from is that I can live without most build steps for a small project… but I can’t live without typescript.

Re: Writing JavaScript without a build system

#30

> But my experience with build systems (not just Javascript build systems!), is that if you have a 5-year-old site, often it’s a huge pain to get the site built again. 5 years? More like 5 minutes in my experience. I probably spend 50% of my time trying to figure out why the build system is breaking, again.

If you put it in docker there's basically a decade guarantee

Not if you want to allow developers to continue using the latest JS patterns, frameworks, libraries, etc.
Post reply on HN