Skip to content

Instantly share code, notes, and snippets.

@davidwallacejackson
Created December 10, 2021 00:37
Show Gist options
  • Select an option

  • Save davidwallacejackson/de8488d2b1dfd0767a8395b76b5c58a8 to your computer and use it in GitHub Desktop.

Select an option

Save davidwallacejackson/de8488d2b1dfd0767a8395b76b5c58a8 to your computer and use it in GitHub Desktop.
import {Plugin} from 'vite';
import fs from 'fs';
const index = fs.readFileSync(__dirname + '/index.html', 'utf-8');
const fileUrls: Plugin = {
name: 'pass-through-file-urls',
configureServer: server => {
server.middlewares.use(async (req, res, next) => {
if (req.url?.match(/.*\/files\/.*$/)) {
res.write(await server.transformIndexHtml(req.url, index));
res.end();
return;
}
next();
});
},
};
export default fileUrls;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment