How to import js file as raw string? #11487
-
I have some client js that I want to import as raw string. In vite, I can append import client from './client.js?raw Is there a cleaner way to do this in Bun than this loader? import { plugin } from 'bun'
plugin({
name: 'Raw Loader',
setup: (build) => {
build.onResolve({ filter: /\?raw$/ }, (args) => {
return {
path: args.path.replaceAll('?raw', ''),
}
})
// Is there a better way than to hardcode client.js here?
build.onLoad({ filter: /client\.js$/ }, async(args) => {
const text = await Bun.file(args.path).text()
return {
exports: {
default: text,
},
loader: 'object',
}
})
},
}) This doesn't seem very clean. I feel like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Have you tried this? import client from "./client.js" with { type: "text" }; |
Beta Was this translation helpful? Give feedback.
-
@Trinovantes how did you manage to make it work with both |
Beta Was this translation helpful? Give feedback.
Have you tried this?