* Plugin to import .md files as raw strings (Bun's text loader behavior).
(extensions: string[])
| 41 | * Plugin to import .md files as raw strings (Bun's text loader behavior). |
| 42 | */ |
| 43 | function rawAssetPlugin(extensions: string[]): Plugin { |
| 44 | return { |
| 45 | name: 'raw-asset', |
| 46 | enforce: 'pre', |
| 47 | resolveId(id, importer) { |
| 48 | if (extensions.some(ext => id.endsWith(ext))) { |
| 49 | // Resolve to actual file path |
| 50 | return this.resolve(id, importer, { skipSelf: true }) |
| 51 | } |
| 52 | return null |
| 53 | }, |
| 54 | load(id) { |
| 55 | if (extensions.some(ext => id.endsWith(ext))) { |
| 56 | const content = readFileSync(id, 'utf-8') |
| 57 | return `export default ${JSON.stringify(content)}` |
| 58 | } |
| 59 | return null |
| 60 | }, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export default defineConfig({ |
| 65 | // CLI tool — no browser features needed |