import { plugin, type BunPlugin } from "bun";

const filePlugin: BunPlugin = {
    name: "File loader",
    async setup(build) {
        build.onLoad({ filter: /\.glsl$/ }, async (args) => {
            const text = await Bun.file(args.path).text();
            return {
                contents: `
                    const text = (${JSON.stringify(text)});                    
                    export default text;
                `,
                loader: 'js',
            };
        });
    }
};

plugin(filePlugin);

export default filePlugin;