Closed phillip-le closed 3 weeks ago
Example is importing an XML file as a string to serve static RSS feed on GET.
XML
string
GET
TypeScript: Add a type declaration ESBuild: Use the file loader
vite:
vite
import { readFileSync } from 'fs'; const xmlRegEx = /\.xml$/; const xmlLoaderPlugin = { name: 'xml-loader', async transform(_ : string, id : string) { if (xmlRegEx.test(id)) { // double check if you can use the `async` version const xml = readFileSync(id).toString(); return { code: `export default \`${xml}\``, }; } return {}; } }
Inspiration: https://github.com/lorenzoc25/vite-plugin-xml-loader
Example is importing an
XML
file as astring
to serve static RSS feed onGET
.TypeScript: Add a type declaration ESBuild: Use the file loader
vite
:Inspiration: https://github.com/lorenzoc25/vite-plugin-xml-loader