Doc: ui/build explain custom build script

This commit is contained in:
Johannes Kirschbauer
2024-12-11 09:53:34 +01:00
parent 53e75475ff
commit cd2b19d4c5

View File

@@ -1,3 +1,12 @@
/**
* This script generates a custom index.html file for the webview UI.
* It reads the manifest.json file generated by Vite and uses it to generate the HTML file.
* It also processes the CSS files to rewrite the URLs in the CSS files to match the new location of the assets.
* The script is run after the Vite build is complete.
*
* This is necessary because the webview UI is loaded from the local file system and the URLs in the CSS files need to be rewritten to match the new location of the assets.
* The generated index.html file is then used as the entry point for the webview UI.
*/
import fs from "node:fs";
import postcss from "postcss";
import path from "node:path";
@@ -43,7 +52,7 @@ fs.readFile(manifestPath, { encoding: "utf8" }, (err, data) => {
console.log(`Rewriting CSS url(): ${asset.url} to ${res}`);
return res;
},
}),
})
)
.process(css, {
from: `dist/${cssEntry}`,