File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Plugin , PluginBuild } from "esbuild" ;
2+ import fs from "node:fs" ;
3+ import path from "node:path" ;
4+
5+ /** Plugin to load `.glsl` files as minified strings */
6+ export const raw : ( ) => Plugin = ( ) => ( {
7+ /** generate randmo name to avoid collision among the plugins */
8+ name : `raw-${ ( Date . now ( ) * Math . random ( ) ) . toString ( 36 ) . slice ( 0 , 8 ) } ` ,
9+ setup ( build : PluginBuild ) {
10+ build . onResolve ( { filter : / \? r a w $ / } , args => {
11+ const filePath = args . path ;
12+ return {
13+ path : filePath ,
14+ pluginData : path . resolve ( args . resolveDir , filePath ) . replace ( / \? r a w $ / , "" ) ,
15+ namespace : "raw" ,
16+ } ;
17+ } ) ;
18+ build . onLoad ( { filter : / \? r a w $ / , namespace : "raw" } , async args => {
19+ return {
20+ contents : fs . readFileSync ( args . pluginData , "utf8" ) ,
21+ loader : "text" ,
22+ } ;
23+ } ) ;
24+ } ,
25+ } ) ;
You can’t perform that action at this time.
0 commit comments