How can I refactor this function, so that it works with vite
:
export function readFileFromDisk(file, folder) {
// console.log(`Reading file ${file} from ${folder}`);
let book = "";
if (typeof folder !== "undefined") {
book = JSON.parse(JSON.stringify(require(`../data/${folder}/${file}`)));
} else {
book = JSON.parse(JSON.stringify(require(`../data/${file}`)));
}
return book;
}
Currently vite reports Uncaught ReferenceError: require is not defined
.
I cannot use import
as it must precede all other statements, which is not possible with this current function syntax.