by simonw · 3y ago · 0 comments
pip install download-esm
download-esm @observablehq/plot
This downloads the ESM version of Observable Plot from the jsDelivr CDN, figures out its dependencies, downloads them as well (40 files total!) and rewrites their imports to be local, not CDN paths.More details here: https://simonwillison.net/2023/May/2/download-esm/
I'm now considering adding import maps support: https://github.com/simonw/download-esm/issues/4
I'm only half kidding, this is pretty cool, but I'm also really sorry that it has come to this for you and your tooling!
- tooling and dependencies are hell in js
- bootstrapping is half the battle in python (see https://bitecode.substack.com/p/relieving-your-python-packag...)
Mix does more than just dependencies, however I am referring the table stakes as being the more narrow scope of dependency management.
You aren’t grabbing ESMs from CDNs for a Node server app. And even if you are, that’s just not a situation that’s happening outside of an ecosystem that straddles client development.
Is there any programming language that does not suffer from dependency hell?
If you know of the npm recipe for doing that I'd love to learn it - I'm fine running npm once to grab the module versions of things (which I intend to vendor in my repo), as long as I don't have to use any build tooling after that point.
https://codeberg.org/macchiato/editor-lib-codemirror/src/bra...
The rollup output is nice. I don't have terser, though I may add it later. When I added a couple exports the diff was just the change in my code.
The library using it can include the integrity attribute and a can go here and run the build after checking the html and JavaScript file and check the output (codeberg.page is like GitHub pages in that it the repo contents controls what it serves): https://macchiato.codeberg.page/editor-lib-codemirror/
There is no build-step, no download- or installation-step, no nothing.
Just... import x from "https://packages.my-domain.net/x@v1.2.3" in JavaScript and it works. All files served locally.
I always assumed, worst that could happen is somebody decides to download all of that CDN's library to my RAM by simply requesting the appropriate URLs until Varnish starts dropping the modules I wanted to cache in the first place.
Thanks to your tip, I can query public datasets with SQL with a one line import in an observable notebook [0] :)
[0] https://observablehq.com/@milesrichardson/madatdata-esm-spli...
It’s basically an http server like npm/http-server, but with all modern tools automagically included.
- A very large subset of Rollup, which is so large that the docs seem to be self-mocking about it
- Another very large subset of ESBuild, which is smaller but still non-trivial
- A whole bunch of Vite-specific stuff that’s only partly (and incompletely/inconsistently) abstracting the omitted portions of those subsets
- An enormous amount of terminology, some very poorly described in any docs if you even know which to consult
- Plugins you’ll definitely need and which are a superset of Rollup’s, and the abstraction is so leaky that you’re often better off skipping the Vite keyword in your searches
I mean, even in the worst case it’s not Webpack, but it’s astonishing how close it can feel very easily.
And I don’t mean this nearly as harshly as it probably sounds. Vite really is great if it’s designed for your use case. But it’s far from the no-headaches panacea even I thought it was a few months ago.
you give it an import map and a list of urls and it either bundles + minifies to a single .js file or rewrites the paths and saves everything as a .zip
deno bundle 'https://esm.sh/@observablehq/plot' > plot.js
My browser development workflow looks somewhat like the following:Imports / versions in importmap.json:
{
"imports": {
"plot": "https://esm.sh/@observablehq/plot@0.6.6"
}
}
Code in app.js: import * as Plot from "plot";
const plot = Plot.rectY({length: 10000}, Plot.binX({y: "count"}, {x: Math.random})).plot();
const div = document.querySelector("#myplot");
div.append(plot);
For development use dev.html: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="importmap" src="./importmap.json"></script>
<script type="module" src="./app.js"></script>
</head>
<body>
<div id="myplot"></div>
</body>
</html>
Then you can then bundle with: deno bundle --import-map=importmap.json app.js > bundle.js
And have as your prod.html: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="module" src="./bundle.js"></script>
</head>
<body>
<div id="myplot"></div>
</body>
</html>
Note that `deno bundle` is deprecated. You can almost replace it with esbuild but it currently lacks builtin support for import maps: deno run --allow-all https://deno.land/x/esbuild@v0.17.18/mod.js --bundle app.js --outfile=bundle.js. # errors, see: https://github.com/evanw/esbuild/issues/2230
I'm really looking forward to the ECMAScript proposal on Type Annotations making it into browsers some days as this would effectively unlock transpiler free typescript development, leaving just a simple optional bundling step for production.https://devblogs.microsoft.com/typescript/a-proposal-for-typ...