compress-shader-literals 1.3.6 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -95,29 +95,29 @@ Real shaders shipped by popular libraries, run through the built-in minifier:
95
95
 
96
96
  | Package | Shaders | Before | After | Saved | Net after Brotli |
97
97
  | ----------------------------- | ------: | ----------: | ----------: | --------: | ---------------: |
98
- | `vtk.js` | 142 | 276,617 B | 159,634 B | **42.3%** | +39.6% |
99
- | `three-stdlib` | 370 | 429,350 B | 272,486 B | **36.5%** | +35.5% |
100
- | `curtainsjs` | 7 | 3,406 B | 2,352 B | **30.9%** | +10.1% |
101
- | `hydra-synth` | 15 | 3,852 B | 2,675 B | **30.6%** | +19.4% |
102
- | `cesium` | 546 | 951,897 B | 664,581 B | **30.2%** | +32.6% |
103
- | `troika-three-utils` | 4 | 168 B | 120 B | **28.6%** | |
104
- | `pixi.js` | 162 | 75,768 B | 56,152 B | **25.9%** | |
105
- | `shader-park-core` | 18 | 10,794 B | 8,007 B | **25.8%** | |
106
- | `@luma.gl/shadertools` | 24 | 149,192 B | 111,095 B | **25.5%** | |
107
- | `three` | 281 | 240,906 B | 185,520 B | **23.0%** | |
108
- | `playcanvas` | 856 | 1,297,844 B | 1,039,365 B | **19.9%** | |
109
- | `ogl` | 22 | 6,109 B | 4,925 B | **19.4%** | |
110
- | `deck.gl` | 132 | 242,113 B | 198,706 B | **17.9%** | |
111
- | `@paper-design/shaders` | 30 | 142,466 B | 122,036 B | **14.3%** | |
112
- | `@deck.gl/layers` | 104 | 223,902 B | 195,827 B | **12.5%** | |
113
- | `@deck.gl/core` | 40 | 17,746 B | 15,738 B | **11.3%** | |
114
- | `@deck.gl/aggregation-layers` | 56 | 43,713 B | 39,094 B | **10.6%** | |
115
- | `@luma.gl/engine` | 29 | 11,357 B | 10,384 B | **8.6%** | |
116
- | `@babylonjs/core` | 349 | 669,740 B | 661,013 B | **1.3%** | |
117
- | `postprocessing` | 136 | 179,705 B | 179,705 B | **0.0%** | |
118
- | **Total** | 3323 | 4,976,645 B | 3,929,415 B | **21.0%** | — |
119
-
120
- _3323 shaders · 2477/3323 parseable shaders (GLSL + WGSL) verified valid after minify · [how this is measured](docs/stats.md) · 2026-07-10_
98
+ | `vtk.js` | 142 | 276,617 B | 157,780 B | **43.0%** | +39.5% |
99
+ | `three-stdlib` | 370 | 429,350 B | 266,774 B | **37.9%** | +35.5% |
100
+ | `curtainsjs` | 7 | 3,406 B | 2,290 B | **32.8%** | +10.4% |
101
+ | `hydra-synth` | 15 | 3,852 B | 2,591 B | **32.7%** | +17.9% |
102
+ | `cesium` | 546 | 951,897 B | 649,851 B | **31.7%** | +32.6% |
103
+ | `troika-three-utils` | 4 | 168 B | 120 B | **28.6%** | +32.3% |
104
+ | `shader-park-core` | 18 | 10,794 B | 7,863 B | **27.2%** | +19.7% |
105
+ | `pixi.js` | 162 | 75,768 B | 55,260 B | **27.1%** | +16.3% |
106
+ | `@luma.gl/shadertools` | 24 | 149,192 B | 109,615 B | **26.5%** | +29.9% |
107
+ | `three` | 281 | 240,906 B | 181,942 B | **24.5%** | +25.5% |
108
+ | `ogl` | 22 | 6,109 B | 4,821 B | **21.1%** | +9.1% |
109
+ | `playcanvas` | 856 | 1,297,844 B | 1,025,421 B | **21.0%** | +49.1% |
110
+ | `deck.gl` | 132 | 242,113 B | 195,406 B | **19.3%** | +31.1% |
111
+ | `@paper-design/shaders` | 30 | 142,466 B | 118,204 B | **17.0%** | +8.9% |
112
+ | `@deck.gl/layers` | 104 | 223,902 B | 192,483 B | **14.0%** | +32.4% |
113
+ | `@deck.gl/core` | 40 | 17,746 B | 15,494 B | **12.7%** | +9.1% |
114
+ | `@deck.gl/aggregation-layers` | 56 | 43,713 B | 38,382 B | **12.2%** | +25.3% |
115
+ | `@luma.gl/engine` | 29 | 11,357 B | 10,206 B | **10.1%** | +3.1% |
116
+ | `@babylonjs/core` | 349 | 669,740 B | 660,843 B | **1.3%** | +2.1% |
117
+ | `postprocessing` | 136 | 179,705 B | 179,705 B | **0.0%** | +0.0% |
118
+ | **Total** | 3323 | 4,976,645 B | 3,875,051 B | **22.1%** | — |
119
+
120
+ _2477/3323 parseable shaders. Verified 2026-07-11. [How this is measured](docs/stats.md)_
121
121
 
122
122
  <!-- STATS:END -->
123
123
 
package/dist/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # compress-shader-literals
2
+
3
+ > **Size matters.** Strip everything strippable from your GLSL & WGSL shaders at build time.
4
+
5
+ > ⭐ Star this repository to support development and help others discover it.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/compress-shader-literals?color=cb3837&logo=npm)](https://www.npmjs.com/package/compress-shader-literals)
8
+ [![minzipped size](https://img.shields.io/bundlephobia/minzip/compress-shader-literals?color=success)](https://bundlephobia.com/package/compress-shader-literals)
9
+ [![npm downloads](https://img.shields.io/npm/dm/compress-shader-literals?color=success)](https://www.npmjs.com/package/compress-shader-literals)
10
+ [![license](https://img.shields.io/npm/l/compress-shader-literals?color=blue)](./LICENSE)
11
+
12
+ A tiny build-time minifier for GLSL & WGSL shaders written as template literals in your JS/TS. Strips comments + whitespace — any bundler, no renaming, no toolchain, no runtime cost.
13
+
14
+ ![Alt Preview](./assets/preview.png)
15
+
16
+ ## Install
17
+
18
+ <!-- [![NPM](https://nodei.co/npm/compress-shader-literals.png)](https://www.npmjs.com/package/compress-shader-literals) -->
19
+
20
+ ```sh
21
+ bun add -d compress-shader-literals
22
+ ```
23
+
24
+ ## About
25
+
26
+ - Removes comments, collapses whitespace, joins statements, and trims space around delimiters. Whitespace and comments only.
27
+ - No renaming, no dead-code removal, no operator-space removal — output stays valid.
28
+ - Runs before your bundler's own minifier.
29
+
30
+ ## Usage
31
+
32
+ One [unplugin](https://github.com/unjs/unplugin) plugin, same API for every bundler:
33
+
34
+ ```js
35
+ import { compressShaderLiterals } from 'compress-shader-literals';
36
+
37
+ // vite.config.js
38
+ export default { plugins: [compressShaderLiterals.vite({ outputRatio: true })] };
39
+ ```
40
+
41
+ For Rollup, webpack, esbuild, Rspack, Rolldown or Farm, call the matching method — `.rollup()`, `.webpack()`, `.esbuild()`, `.rspack()`, `.rolldown()`, `.farm()` — with the same options.
42
+
43
+ Finds tagged and comment-prefixed literals. The comment form keeps editor syntax highlighting:
44
+
45
+ ```ts
46
+ const vert = glsl`
47
+ // vertex shader ← stripped
48
+ precision highp float;
49
+ void main() { gl_Position = vec4(0.0); }
50
+ `;
51
+
52
+ const frag = /* wgsl */ `
53
+ /* fragment */
54
+ fn main() {}
55
+ `;
56
+ ```
57
+
58
+ **Options**
59
+
60
+ | Option | Default | Description |
61
+ | ------------- | ---------------------------- | -------------------------------------------------------------------------- |
62
+ | `tags` | `['glsl', 'wgsl', 'shader']` | Tag names / comment markers to match |
63
+ | `scan` | `'ast'` | `'ast'` parses the file with Babel; `'loose'` matches by regex — see below |
64
+ | `include` | `[/\.[mc]?[jt]sx?$/]` | Files to process — the JS/TS family Babel can parse |
65
+ | `exclude` | `[/node_modules/, /dist/]` | Files to skip — dependencies are skipped by default |
66
+ | `outputRatio` | `false` | Print a bytes-saved summary after build |
67
+ | `transform` | built-in `minifyShader` | Custom minifier — `(shader: string) => string` |
68
+ | `debug` | `false` | Log each file's discovered literals to the console |
69
+
70
+ **`scan: 'loose'`** — for files Babel can't parse (anything that isn't plain JS/TS: Svelte components, Astro components, etc). Instead of a whole-file AST parse, it matches the same tagged/comment-prefixed literal shapes by regex. Opt in and point `include` at the files yourself — there's no whole-file syntax guarantee, so a match is only touched once its content also looks like a real shader:
71
+
72
+ ```js
73
+ compressShaderLiterals.vite({ scan: 'loose', include: [/\.svelte$/] });
74
+ ```
75
+
76
+ **Programmatic API** — the core helpers are exported for tooling authors (validators, ESLint rules, CLIs), no plugin required:
77
+
78
+ ```js
79
+ import { extractShaderLiterals, extractShaderLiteralsLoose, minifyShader } from 'compress-shader-literals';
80
+
81
+ extractShaderLiterals('const v = glsl`void main() {}`');
82
+ // → [{ tag: 'glsl', value: 'void main() {}', start: 14, end: 30 }]
83
+
84
+ extractShaderLiteralsLoose('<script>const v = glsl`void main() {}`</script>');
85
+ // → same shape, found by regex instead of a Babel parse
86
+
87
+ minifyShader('// comment\nvoid main() {}'); // → 'void main() {}'
88
+ ```
89
+
90
+ ## Stats
91
+
92
+ Real shaders shipped by popular libraries, run through the built-in minifier:
93
+
94
+ <!-- STATS:START -->
95
+
96
+ | Package | Shaders | Before | After | Saved | Net after Brotli |
97
+ | ----------------------------- | ------: | ----------: | ----------: | --------: | ---------------: |
98
+ | `vtk.js` | 142 | 276,617 B | 157,780 B | **43.0%** | +39.5% |
99
+ | `three-stdlib` | 370 | 429,350 B | 266,774 B | **37.9%** | +35.5% |
100
+ | `curtainsjs` | 7 | 3,406 B | 2,290 B | **32.8%** | +10.4% |
101
+ | `hydra-synth` | 15 | 3,852 B | 2,591 B | **32.7%** | +17.9% |
102
+ | `cesium` | 546 | 951,897 B | 649,851 B | **31.7%** | +32.6% |
103
+ | `troika-three-utils` | 4 | 168 B | 120 B | **28.6%** | +32.3% |
104
+ | `shader-park-core` | 18 | 10,794 B | 7,863 B | **27.2%** | +19.7% |
105
+ | `pixi.js` | 162 | 75,768 B | 55,260 B | **27.1%** | +16.3% |
106
+ | `@luma.gl/shadertools` | 24 | 149,192 B | 109,615 B | **26.5%** | +29.9% |
107
+ | `three` | 281 | 240,906 B | 181,942 B | **24.5%** | +25.5% |
108
+ | `ogl` | 22 | 6,109 B | 4,821 B | **21.1%** | +9.1% |
109
+ | `playcanvas` | 856 | 1,297,844 B | 1,025,421 B | **21.0%** | +49.1% |
110
+ | `deck.gl` | 132 | 242,113 B | 195,406 B | **19.3%** | +31.1% |
111
+ | `@paper-design/shaders` | 30 | 142,466 B | 118,204 B | **17.0%** | +8.9% |
112
+ | `@deck.gl/layers` | 104 | 223,902 B | 192,483 B | **14.0%** | +32.4% |
113
+ | `@deck.gl/core` | 40 | 17,746 B | 15,494 B | **12.7%** | +9.1% |
114
+ | `@deck.gl/aggregation-layers` | 56 | 43,713 B | 38,382 B | **12.2%** | +25.3% |
115
+ | `@luma.gl/engine` | 29 | 11,357 B | 10,206 B | **10.1%** | +3.1% |
116
+ | `@babylonjs/core` | 349 | 669,740 B | 660,843 B | **1.3%** | +2.1% |
117
+ | `postprocessing` | 136 | 179,705 B | 179,705 B | **0.0%** | +0.0% |
118
+ | **Total** | 3323 | 4,976,645 B | 3,875,051 B | **22.1%** | — |
119
+
120
+ _2477/3323 parseable shaders. ✅ Verified 2026-07-11. [How this is measured](docs/stats.md)_
121
+
122
+ <!-- STATS:END -->
123
+
124
+ ## How it works
125
+
126
+ 1. Parses each matched file with Babel — `.js`, `.jsx`, `.ts`, `.tsx`, `.mjs`, `.cjs`, `.mts`, `.cts` by default. `scan: 'loose'` skips the parse and matches by regex instead, for files Babel can't parse.
127
+ 2. Finds tagged (`` glsl`…` ``) and comment-prefixed (`/* glsl */ \`…\``) literals, skipping any with `${…}` interpolation.
128
+ 3. Strips comments, collapses whitespace, and joins statements onto one line — keeping real newlines around `#` preprocessor directives and `\` line-continuations (which are newline-sensitive). Whitespace hugging a delimiter (`( ) { } ; ,`) is removed entirely; whitespace around operators (and `=`, to stay WGSL-generic-safe) is preserved, so adjacent tokens never merge.
129
+ 4. Rewrites the literal in place with [magic-string](https://github.com/Rich-Harris/magic-string), so sourcemaps stay intact.
130
+ 5. Runs as a `pre` transform, so your bundler's own minifier still sees the result.
131
+
132
+ ## Issues & compatibility
133
+
134
+ If you run into any problems — wrong output, a shader pattern that isn't picked up, or a library that doesn't play nicely — please [open an issue](https://github.com/jayf0x/compress-shader-literals/issues) or just mention which library you're using and I'll add it to the test suite.
135
+
136
+ ## License
137
+
138
+ [MIT](./LICENSE) © [jayF0x](https://github.com/jayf0x)
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("@rollup/pluginutils"),l=require("byte-snap"),u=require("magic-string");u=s(u,1);let d=require("unplugin"),f=require("@babel/parser"),p=require("@babel/traverse");p=s(p,1);var m=[`glsl`,`wgsl`,`shader`],h=[/\.[mc]?[jt]sx?$/],g=[/node_modules/,/dist/],_=e=>RegExp(`^\\s*(${e.join(`|`)})\\s*$`),v=/\b(gl_FragColor|gl_Position|void\s+main|precision\s+(highp|mediump|lowp)|fn\s+main)\b/,y=/\r\n/g,b=/\/\*[\s\S]*?\*\//g,x=/\/\/.*$/gm,S=/[ \t]+/g,C=/\s*([(){};,])\s*/g,w=p.default.default||p.default,T=(e,t=m)=>{let n=new Set(t),r=_(t),i=[];try{w((0,f.parse)(e,{sourceType:`module`,plugins:[`typescript`,`jsx`,`decorators-legacy`],allowReturnOutsideFunction:!0}),{TaggedTemplateExpression(e){let{tag:t,quasi:r}=e.node,a=null;t.type===`Identifier`&&n.has(t.name)?a=t.name:t.type===`MemberExpression`&&t.property.type===`Identifier`&&n.has(t.property.name)&&(a=t.property.name),a&&r.expressions.length===0&&i.push({tag:a,value:r.quasis[0].value.raw,start:r.start,end:r.end})},TemplateLiteral(e){let t=e.node;if(t.expressions.length>0)return;let n=t.leadingComments||e.parentPath?.node?.leadingComments||[];for(let e of n){if(!e||e.type!==`CommentBlock`)continue;let n=e.value.match(r);if(n){i.push({tag:n[1],value:t.quasis[0].value.raw,start:t.start,end:t.end});break}}}})}catch(e){if(e.name!==`SyntaxError`)throw e}return i},E=(e,t)=>{for(let n=t;n<e.length;n++)if(e[n]===`\\`)n++;else if(e[n]==="`")return n;return-1},D=(e,t=m)=>{let n=t.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`),r=RegExp(`\\b(${n})\\s*\`|/\\*\\s*(${n})\\s*\\*/\\s*\``,`g`),i=[],a;for(;a=r.exec(e);){let t=a.index+a[0].length,n=E(e,t);if(n===-1)continue;let o=e.slice(t,n);!o.includes("${")&&v.test(o)&&i.push({tag:a[1]??a[2],value:o,start:t-1,end:n+1}),r.lastIndex=n+1}return i},O=e=>{let t=e.replace(y,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("@rollup/pluginutils"),l=require("byte-snap"),u=require("magic-string");u=s(u,1);let d=require("unplugin"),f=require("@babel/parser"),p=require("@babel/traverse");p=s(p,1);var m=[`glsl`,`wgsl`,`shader`],h=[/\.[mc]?[jt]sx?$/],g=[/node_modules/,/dist/],_=e=>RegExp(`^\\s*(${e.join(`|`)})\\s*$`),v=/\b(gl_FragColor|gl_Position|void\s+main|precision\s+(highp|mediump|lowp)|fn\s+main)\b/,y=/\r\n/g,b=/\/\*[\s\S]*?\*\//g,x=/\/\/.*$/gm,S=/[ \t]+/g,C=/\s*([(){};,])\s*/g,w=/@vertex|@fragment|@group|var<|@compute/,T=e=>w.test(e)&&!/void\s+main/.test(e),E=/(?<!>)\s+=\s+/g,D=p.default.default||p.default,O=(e,t=m)=>{let n=new Set(t),r=_(t),i=[];try{D((0,f.parse)(e,{sourceType:`module`,plugins:[`typescript`,`jsx`,`decorators-legacy`],allowReturnOutsideFunction:!0}),{TaggedTemplateExpression(e){let{tag:t,quasi:r}=e.node,a=null;t.type===`Identifier`&&n.has(t.name)?a=t.name:t.type===`MemberExpression`&&t.property.type===`Identifier`&&n.has(t.property.name)&&(a=t.property.name),a&&r.expressions.length===0&&i.push({tag:a,value:r.quasis[0].value.raw,start:r.start,end:r.end})},TemplateLiteral(e){let t=e.node;if(t.expressions.length>0)return;let n=t.leadingComments||e.parentPath?.node?.leadingComments||[];for(let e of n){if(!e||e.type!==`CommentBlock`)continue;let n=e.value.match(r);if(n){i.push({tag:n[1],value:t.quasis[0].value.raw,start:t.start,end:t.end});break}}}})}catch(e){if(e.name!==`SyntaxError`)throw e}return i},k=(e,t)=>{for(let n=t;n<e.length;n++)if(e[n]===`\\`)n++;else if(e[n]==="`")return n;return-1},A=(e,t=m)=>{let n=t.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`),r=RegExp(`\\b(${n})\\s*\`|/\\*\\s*(${n})\\s*\\*/\\s*\``,`g`),i=[],a;for(;a=r.exec(e);){let t=a.index+a[0].length,n=k(e,t);if(n===-1)continue;let o=e.slice(t,n);!o.includes("${")&&v.test(o)&&i.push({tag:a[1]??a[2],value:o,start:t-1,end:n+1}),r.lastIndex=n+1}return i},j=e=>{let t=e.replace(y,`
2
2
  `).replace(b,``).replace(x,``).split(`
3
3
  `).map(e=>e.replace(S,` `).trim()).filter(Boolean),n=``,r=!1;for(let e of t)e.startsWith(`#`)||r?n+=(n&&!n.endsWith(`
4
4
  `)?`
5
5
  `:``)+e+`
6
6
  `:n+=n===``||n.endsWith(`
7
- `)?e:` `+e,r=e.endsWith(`\\`);return r=!1,n=n.split(`
8
- `).map(e=>{let t=e.startsWith(`#`)||r?e:e.replace(C,`$1`);return r=e.endsWith(`\\`),t}).join(`
9
- `),n.trim()},k=(0,d.createUnplugin)((e={})=>{let t=e.tags||m,n=e.transform||O,r=e.scan===`loose`?D:T,i=(0,c.createFilter)(e.include||h,e.exclude||g),a=``,o=``,s=0;return{name:`compress-shader-literals`,enforce:`pre`,transform(c,l){if(!i(l)||!t.some(e=>c.includes(e)))return null;let d=r(c,t);if(d.length===0)return null;e.debug&&console.log(`[compress-shader-literals] ${l}: ${d.length} literal(s) — ${d.map(e=>e.tag).join(`, `)}`);let f=new u.default(c),p=!1;for(let t of d){let r=n(t.value);t.value!==r&&(f.overwrite(t.start,t.end,`\`${r}\``),p=!0),e.outputRatio&&(a+=t.value,o+=r,s++)}return p?{code:f.toString(),map:f.generateMap({hires:!0,source:l})}:null},buildEnd(){if(e.outputRatio&&a){let e=`compress-shader-literals: ${s} shader literal${s===1?``:`s`}`;(0,l.diff)(l.snap.text(a),l.snap.text(o)).print(e)}}}});exports.compressShaderLiterals=k,exports.extractShaderLiterals=T,exports.minifyShader=O;
7
+ `)?e:` `+e,r=e.endsWith(`\\`);let i=T(n);return r=!1,n=n.split(`
8
+ `).map(e=>{if(e.startsWith(`#`)||r)return r=e.endsWith(`\\`),e;let t=e.replace(C,`$1`);return i||(t=t.replace(E,`=`)),r=e.endsWith(`\\`),t}).join(`
9
+ `),n.trim()},M=(0,d.createUnplugin)((e={})=>{let t=e.tags||m,n=e.transform||j,r=e.scan===`loose`?A:O,i=(0,c.createFilter)(e.include||h,e.exclude||g),a=``,o=``,s=0;return{name:`compress-shader-literals`,enforce:`pre`,transform(c,l){if(!i(l)||!t.some(e=>c.includes(e)))return null;let d=r(c,t);if(d.length===0)return null;e.debug&&console.log(`[compress-shader-literals] ${l}: ${d.length} literal(s) — ${d.map(e=>e.tag).join(`, `)}`);let f=new u.default(c),p=!1;for(let t of d){let r=n(t.value);t.value!==r&&(f.overwrite(t.start,t.end,`\`${r}\``),p=!0),e.outputRatio&&(a+=t.value,o+=r,s++)}return p?{code:f.toString(),map:f.generateMap({hires:!0,source:l})}:null},buildEnd(){if(e.outputRatio&&a){let e=`compress-shader-literals: ${s} shader literal${s===1?``:`s`}`;(0,l.diff)(l.snap.text(a),l.snap.text(o)).print(e)}}}});exports.compressShaderLiterals=M,exports.extractShaderLiterals=O,exports.minifyShader=j;
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ var s = [
9
9
  "glsl",
10
10
  "wgsl",
11
11
  "shader"
12
- ], c = [/\.[mc]?[jt]sx?$/], l = [/node_modules/, /dist/], u = (e) => RegExp(`^\\s*(${e.join("|")})\\s*$`), d = /\b(gl_FragColor|gl_Position|void\s+main|precision\s+(highp|mediump|lowp)|fn\s+main)\b/, f = /\r\n/g, p = /\/\*[\s\S]*?\*\//g, m = /\/\/.*$/gm, h = /[ \t]+/g, g = /\s*([(){};,])\s*/g, _ = o.default || o, v = (e, t = s) => {
12
+ ], c = [/\.[mc]?[jt]sx?$/], l = [/node_modules/, /dist/], u = (e) => RegExp(`^\\s*(${e.join("|")})\\s*$`), d = /\b(gl_FragColor|gl_Position|void\s+main|precision\s+(highp|mediump|lowp)|fn\s+main)\b/, f = /\r\n/g, p = /\/\*[\s\S]*?\*\//g, m = /\/\/.*$/gm, h = /[ \t]+/g, g = /\s*([(){};,])\s*/g, _ = /@vertex|@fragment|@group|var<|@compute/, v = (e) => _.test(e) && !/void\s+main/.test(e), y = /(?<!>)\s+=\s+/g, b = o.default || o, x = (e, t = s) => {
13
13
  let n = new Set(t), r = u(t), i = [];
14
14
  try {
15
- _(a(e, {
15
+ b(a(e, {
16
16
  sourceType: "module",
17
17
  plugins: [
18
18
  "typescript",
@@ -53,14 +53,14 @@ var s = [
53
53
  if (e.name !== "SyntaxError") throw e;
54
54
  }
55
55
  return i;
56
- }, y = (e, t) => {
56
+ }, S = (e, t) => {
57
57
  for (let n = t; n < e.length; n++) if (e[n] === "\\") n++;
58
58
  else if (e[n] === "`") return n;
59
59
  return -1;
60
- }, b = (e, t = s) => {
60
+ }, C = (e, t = s) => {
61
61
  let n = t.map((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), r = RegExp(`\\b(${n})\\s*\`|/\\*\\s*(${n})\\s*\\*/\\s*\``, "g"), i = [], a;
62
62
  for (; a = r.exec(e);) {
63
- let t = a.index + a[0].length, n = y(e, t);
63
+ let t = a.index + a[0].length, n = S(e, t);
64
64
  if (n === -1) continue;
65
65
  let o = e.slice(t, n);
66
66
  !o.includes("${") && d.test(o) && i.push({
@@ -71,15 +71,17 @@ var s = [
71
71
  }), r.lastIndex = n + 1;
72
72
  }
73
73
  return i;
74
- }, x = (e) => {
74
+ }, w = (e) => {
75
75
  let t = e.replace(f, "\n").replace(p, "").replace(m, "").split("\n").map((e) => e.replace(h, " ").trim()).filter(Boolean), n = "", r = !1;
76
76
  for (let e of t) e.startsWith("#") || r ? n += (n && !n.endsWith("\n") ? "\n" : "") + e + "\n" : n += n === "" || n.endsWith("\n") ? e : " " + e, r = e.endsWith("\\");
77
+ let i = v(n);
77
78
  return r = !1, n = n.split("\n").map((e) => {
78
- let t = e.startsWith("#") || r ? e : e.replace(g, "$1");
79
- return r = e.endsWith("\\"), t;
79
+ if (e.startsWith("#") || r) return r = e.endsWith("\\"), e;
80
+ let t = e.replace(g, "$1");
81
+ return i || (t = t.replace(y, "=")), r = e.endsWith("\\"), t;
80
82
  }).join("\n"), n.trim();
81
- }, S = i((i = {}) => {
82
- let a = i.tags || s, o = i.transform || x, u = i.scan === "loose" ? b : v, d = e(i.include || c, i.exclude || l), f = "", p = "", m = 0;
83
+ }, T = i((i = {}) => {
84
+ let a = i.tags || s, o = i.transform || w, u = i.scan === "loose" ? C : x, d = e(i.include || c, i.exclude || l), f = "", p = "", m = 0;
83
85
  return {
84
86
  name: "compress-shader-literals",
85
87
  enforce: "pre",
@@ -110,4 +112,4 @@ var s = [
110
112
  };
111
113
  });
112
114
  //#endregion
113
- export { S as compressShaderLiterals, v as extractShaderLiterals, x as minifyShader };
115
+ export { T as compressShaderLiterals, x as extractShaderLiterals, w as minifyShader };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compress-shader-literals",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "type": "module",
5
5
  "description": "✂️ Strip comments & whitespace from GLSL/WGSL shader literals in your JS/TS at build time — any bundler, no toolchain, no runtime cost.",
6
6
  "main": "./dist/index.cjs",
@@ -45,8 +45,10 @@
45
45
  "devDependencies": {
46
46
  "@size-limit/file": "^11.0.0",
47
47
  "@trivago/prettier-plugin-sort-imports": "^5.0.0",
48
+ "plugin-include": "^1.0.2",
48
49
  "prettier": "^3.0.0",
49
50
  "size-limit": "^11.0.0",
51
+ "taglify": "^1.0.5",
50
52
  "typescript": "^5.6.0",
51
53
  "vite": "^8.1.0"
52
54
  },