Run scripts in a vite project with vite-node
While building the Burning Wheel index on this site, I’ve written a small command line tool to manage the index database. This tool shares some code with the site proper. As anyone who has ever used Typescript directly will know, managing different tsconfig.json
files, and the various targets, modules, output files, etc can quickly become an absolute quagmire. I wasn’t surprised to have trouble getting it to build.
It turns out that for projects using Vite (such as with Astro or Svelte) the vite-node
package lets you trivially run any TypeScript file in your project as a script, using the existing configuration. Honestly, it’s a bit like magic.