Skip to content

Instantly share code, notes, and snippets.

@emrergin
Last active November 30, 2022 21:13
Show Gist options
  • Save emrergin/bf75a15be053c4994a24f9021dd25c09 to your computer and use it in GitHub Desktop.
Save emrergin/bf75a15be053c4994a24f9021dd25c09 to your computer and use it in GitHub Desktop.
Vite Unserved HTML Workaround
import { readFileSync,writeFileSync } from 'fs';
const basePath='ENTERBASEPATHHERE';
function modifyForLocal(basePath){
const regex = new RegExp('"'+basePath, "g");
const htmlToBeUpdated = readFileSync( './dist/index.html', {encoding:'utf8', flag:'r'});
const result = htmlToBeUpdated.replace(/type="module" crossorigin/g, "defer")
.replace(regex,`"./`);
writeFileSync('./dist/index.html',result);
}
modifyForLocal(basePath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment