Okay so in essence I changed from reading directly from the filesystem to reading from vite's bundled imported modules/files in build time which was used with import.meta.glob
Previous Implementation, reading directly from filesystem (matter.read uses readFileSync):
1function processPost(path: string) {2 const { data, content } = matter.read(path); // Read with fs module3 ....4}56function getPosts() {7 const postFiles = import.meta.glob('/src/lib/posts/*.svx');8 const baseDir = path.resolve();91011 const posts = Object.keys(postFiles).map((filePath) => {12 const absolutePath = path.resolve(baseDir + filePath);13 return processPost(absolutePath);14 });15....16}
Working Implementation:
1export const processPost = async (path: string, slug: string): Promise<IPost> => {2 const asset = read(path); // read with svelte's read function3 const text = await asset.text();4 const { data, content } = matter(text);56....7};89export const getPosts = async (): Promise<Posts> => {10 const postFiles = import.meta.glob<string>('../../posts/*.svx', {11 query: '?url',12 eager: true,13 import: "default"14 });1516 let posts: Posts = [];17 for (const key in postFiles) {18 const post = await processPost(postFiles[key], slug);19 posts.push(post);20 }2122....23};