If you're happy with a single bundled file, another option is:
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...
https://github.com/tc39/proposal-type-annotations