DEV Community

TK
TK

Posted on

How to import raw file with import.meta.glob() funciton of vite.js

When I use SvelteKit for blog system and I wanted to import markdown file as raw, so I use function of vite lie below


import.meta.glob('../data/*.md')

Enter fullscreen mode Exit fullscreen mode

But it didn't work.
Then the function occured error like below.

throw new Error(Parse failure: ${err.message}\\nContents of line ${line}: ${code.split('\\n')[line - 1]});
Enter fullscreen mode Exit fullscreen mode

Because I didn't configure settings of .md file.
I could solve the problem with vite-raw-plugin.

Top comments (1)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

According to the docs - vitejs.dev/guide/features.html#glo...

import.meta.glob('../data/*.md', { as: 'raw' })
Enter fullscreen mode Exit fullscreen mode