I'm trying to use an external script to create static-generated content (SSG) but can't figure out how to plug it into Vite.
I've looked into plugins like vite-plugin-run but that dosn't seem to be able and get the file that changed to pass into the command. I also looked into transform
hook but can't manage to get something working.
Is it possible to do something like below? How can I pass the source to the command (aka redirect content as input to command)?
// vite.config.js
import { exec } from 'child_process';
...
plugins: [
{
name: "Transform HTML",
transform(code, id) {
// Transform HTML via external script
if (id.endsWith(".html")) {
// TODO: Replace 'echo test' with actually passing the content to myscript.sh and using the output
exec('echo test', (err, stdout, stderr) => {
code = stdout;
});
}
return {code, map: null}
}
}
]