esbuild-plugin-glsl
Advanced tools
Comparing version 1.1.1 to 1.2.0
/** | ||
* esbuild-plugin-glsl v1.1.1 build Sun Mar 12 2023 | ||
* esbuild-plugin-glsl v1.2.0 build Thu Apr 13 2023 | ||
* https://github.com/vanruesc/esbuild-plugin-glsl | ||
@@ -7,5 +7,5 @@ * Copyright 2023 Raoul van Rüschen | ||
*/ | ||
import*as p from"fs";import*as g from"util";function u(o){let n=/[ \t]*(?:(?:\/\*[\s\S]*?\*\/)|(?:\/\/.*\n))/g,a=/\s*([{}=*,+/><&|[\]()\\!?:;-])\s*/g,i=/(\w<\w+>)\s*(\w)/g,r=o.replace(/\r/g,"").replace(n,""),e=!0,l=!1;return r=r.split(/\n+/).reduce((s,t)=>(t=t.trim().replace(/\s{2,}|\t/," "),t[0]==="#"?(l&&s.push(` | ||
`),s.push(t,` | ||
`),l=!1):t.length>0&&(t=t.replace(a,"$1"),!e&&/\w/.test(t[0])&&(t=" "+t),t=t.replace(i,"$1 $2"),s.push(t),e=!/\w/.test(t[t.length-1]),l=!0),s),[]).join(""),r.replace(/\n{2,}/g,` | ||
`)}function d({minify:o=!1}={}){let n=g.promisify(p.readFile);return{name:"glsl",setup(a){async function i(r){let e=await n(r.path,"utf8");return{contents:o?u(e):e,loader:"text"}}a.onLoad({filter:/\.(?:frag|vert|glsl|wgsl)$/},i)}}}export{d as default,d as glsl}; | ||
function x(i){let o=/[ \t]*(?:(?:\/\*[\s\S]*?\*\/)|(?:\/\/.*\n))/g,l=/\s*([{}=*,+/><&|[\]()\\!?:;-])\s*/g,e=/(\w<\w+>)\s*(\w)/g,r=i.replace(/\r/g,"").replace(o,""),a=!0,s=!1;return r=r.split(/\n+/).reduce((n,t)=>(t=t.trim().replace(/\s{2,}|\t/," "),t[0]==="#"?(s&&n.push(` | ||
`),n.push(t,` | ||
`),s=!1):t.length>0&&(t=t.replace(l,"$1"),!a&&/\w/.test(t[0])&&(t=" "+t),t=t.replace(e,"$1 $2"),n.push(t),a=!/\w/.test(t[t.length-1]),s=!0),n),[]).join(""),r.replace(/\n{2,}/g,` | ||
`)}import*as L from"fs";import*as y from"util";import*as f from"path";var O=y.promisify(L.readFile),d=/#include +["']([.\\/\w-]+)["']/g,S=/\r|\n|\r\n/g;async function m(i,o,l){let e=await O(i,"utf8");if(!l)return{contents:e};let r=[],a=[],s=new Set;o.set(i,e);let n=d.exec(e);for(;n!==null;){let t=n[0],u=n[1],c=f.join(f.dirname(i),u);try{if(!o.has(c)){let p=await m(c,o,l);p.warnings?.forEach(g=>a.push(g)),p.watchFiles?.forEach(g=>s.add(g)),e=p.contents,o.set(c,e)}r.push({file:c,contents:e,target:t}),s.add(c),n=d.exec(e)}catch{if(n===null)break;let g=e.split(S),h=g.indexOf(n[0]),w=g[h];a.push({text:`File from <${n[0]}> not found`,location:{file:u,line:h+1,length:u.length,column:w.indexOf(u),lineText:w}}),r.push({file:c,contents:"",target:n[0]}),n=d.exec(e)}}for(let t of r)e=e.replace(t.target,t.contents);return{contents:e,warnings:a,watchFiles:[...s]}}function E({minify:i=!1,resolveIncludes:o=!0}={}){let l=new Map;return{name:"glsl",setup(e){async function r(a){let{contents:s,warnings:n,watchFiles:t}=await m(a.path,l,o);return{contents:i?x(s):s,warnings:n,watchFiles:t,loader:"text"}}e.onLoad({filter:/\.(?:frag|vert|glsl|wgsl)$/},r)}}}export{E as default,E as glsl}; |
@@ -6,3 +6,15 @@ import { Plugin } from "esbuild"; | ||
export interface GLSLOptions { | ||
/** | ||
* Enables or disables shader minification. | ||
* | ||
* Default is `false`. | ||
*/ | ||
minify?: boolean; | ||
/** | ||
* Enables or disables shader include resolution. | ||
* When enabled, shaders can be included with the custom `#include "path"` directive. | ||
* | ||
* Default is `true`. | ||
*/ | ||
resolveIncludes?: boolean; | ||
} | ||
@@ -15,3 +27,3 @@ /** | ||
*/ | ||
declare function glsl({ minify }?: GLSLOptions): Plugin; | ||
declare function glsl({ minify, resolveIncludes }?: GLSLOptions): Plugin; | ||
export { glsl, glsl as default }; |
{ | ||
"name": "esbuild-plugin-glsl", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A GLSL plugin for esbuild.", | ||
"homepage": "https://github.com/vanruesc/esbuild-plugin-glsl", | ||
"license": "Zlib", | ||
"type": "module", | ||
"sideEffects": false, | ||
"main": "dist/esbuild-plugin-glsl.cjs", | ||
"module": "dist/esbuild-plugin-glsl.js", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
"import": "./dist/esbuild-plugin-glsl.js", | ||
"require": "./dist/esbuild-plugin-glsl.cjs" | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"import": "./dist/esbuild-plugin-glsl.js", | ||
"require": "./dist/esbuild-plugin-glsl.cjs" | ||
} | ||
}, | ||
"type": "module", | ||
"sideEffects": false, | ||
"license": "Zlib", | ||
"keywords": [ | ||
@@ -16,0 +20,0 @@ "esbuild", |
@@ -27,5 +27,10 @@ # esbuild-plugin-glsl | ||
})] | ||
}).catch(() => process.exit(1)); | ||
}); | ||
``` | ||
### Options | ||
* `minify`: Enables or disables basic shader minification. Default is `false`. | ||
* `resolveIncludes`: When enabled, shaders can include other shaders with the custom `#include "path"` directive. Default is `true`. | ||
### TypeScript | ||
@@ -32,0 +37,0 @@ |
Sorry, the diff of this file is not supported yet
10020
8
82
64