compress-shader-literals 1.1.3 → 1.2.0
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 +14 -9
- package/dist/index.cjs +7 -3
- package/dist/index.js +12 -8
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ A build-time minifier that strips comments and whitespace from GLSL & WGSL shade
|
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
|
+
[](https://www.npmjs.com/package/compress-shader-literals)
|
|
19
|
+
|
|
18
20
|
```sh
|
|
19
21
|
bun add -d compress-shader-literals
|
|
20
22
|
# or: npm i -D compress-shader-literals
|
|
@@ -84,15 +86,18 @@ Real shaders shipped by popular libraries, run through the built-in minifier:
|
|
|
84
86
|
|
|
85
87
|
<!-- STATS:START -->
|
|
86
88
|
|
|
87
|
-
| Package
|
|
88
|
-
|
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `shader-park-core`
|
|
92
|
-
| `
|
|
93
|
-
|
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
| Package | Shaders | Before | After | Saved |
|
|
90
|
+
| ----------------------- | ------: | ----------: | ----------: | --------: |
|
|
91
|
+
| `curtainsjs` | 7 | 3,406 B | 2,485 B | **27.0%** |
|
|
92
|
+
| `pixi.js` | 162 | 75,768 B | 59,432 B | **21.6%** |
|
|
93
|
+
| `shader-park-core` | 18 | 10,794 B | 8,721 B | **19.2%** |
|
|
94
|
+
| `three` | 281 | 240,772 B | 197,399 B | **18.0%** |
|
|
95
|
+
| `ogl` | 22 | 6,109 B | 5,182 B | **15.2%** |
|
|
96
|
+
| `@paper-design/shaders` | 30 | 142,466 B | 129,723 B | **8.9%** |
|
|
97
|
+
| `@babylonjs/core` | 349 | 669,740 B | 664,617 B | **0.8%** |
|
|
98
|
+
| **Total** | 869 | 1,149,055 B | 1,067,559 B | **7.1%** |
|
|
99
|
+
|
|
100
|
+
_869 shaders · 558/558 parseable GLSL verified valid after minify · [how this is measured](docs/stats.md) · 2026-07-01_
|
|
96
101
|
|
|
97
102
|
<!-- STATS:END -->
|
|
98
103
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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=p.default.default||p.default,
|
|
2
|
-
`).replace(
|
|
3
|
-
`).
|
|
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=/\r\n/g,y=/\/\*[\s\S]*?\*\//g,b=/\/\/.*$/gm,x=/[ \t]+/g,S=p.default.default||p.default,C=(e,t=m)=>{let n=new Set(t),r=_(t),i=[];try{S((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},w=e=>{let t=e.replace(v,`
|
|
2
|
+
`).replace(y,``).replace(b,``).split(`
|
|
3
|
+
`).map(e=>e.replace(x,` `).trim()).filter(Boolean),n=``,r=!1;for(let e of t)e.startsWith(`#`)||r?n+=(n&&!n.endsWith(`
|
|
4
|
+
`)?`
|
|
5
|
+
`:``)+e+`
|
|
6
|
+
`:n+=n===``||n.endsWith(`
|
|
7
|
+
`)?e:` `+e,r=e.endsWith(`\\`);return n.trim()},T=(0,d.createUnplugin)((e={})=>{let t=e.tags||m,n=e.transform||w,r=(0,c.createFilter)(e.include||h,e.exclude||g),i=``,a=``;return{name:`compress-shader-literals`,enforce:`pre`,transform(o,s){if(!r(s)||!t.some(e=>o.includes(e)))return null;let c=C(o,t);if(c.length===0)return null;e.debug&&console.log(`[compress-shader-literals] ${s}: ${c.length} literal(s) — ${c.map(e=>e.tag).join(`, `)}`);let l=new u.default(o),d=!1;for(let t of c){let r=n(t.value);t.value!==r&&(l.overwrite(t.start,t.end,`\`${r}\``),d=!0),e.outputRatio&&(i+=t.value,a+=r)}return d?{code:l.toString(),map:l.generateMap({hires:!0,source:s})}:null},buildEnd(){e.outputRatio&&i&&(0,l.diff)(l.snap.text(i),l.snap.text(a)).print()}}});exports.compressShaderLiterals=T,exports.extractShaderLiterals=C,exports.minifyShader=w;
|
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 = o.default || o,
|
|
12
|
+
], c = [/\.[mc]?[jt]sx?$/], l = [/node_modules/, /dist/], u = (e) => RegExp(`^\\s*(${e.join("|")})\\s*$`), d = /\r\n/g, f = /\/\*[\s\S]*?\*\//g, p = /\/\/.*$/gm, m = /[ \t]+/g, h = o.default || o, g = (e, t = s) => {
|
|
13
13
|
let n = new Set(t), r = u(t), i = [];
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
h(a(e, {
|
|
16
16
|
sourceType: "module",
|
|
17
17
|
plugins: [
|
|
18
18
|
"typescript",
|
|
@@ -53,20 +53,24 @@ var s = [
|
|
|
53
53
|
if (e.name !== "SyntaxError") throw e;
|
|
54
54
|
}
|
|
55
55
|
return i;
|
|
56
|
-
},
|
|
57
|
-
let
|
|
56
|
+
}, _ = (e) => {
|
|
57
|
+
let t = e.replace(d, "\n").replace(f, "").replace(p, "").split("\n").map((e) => e.replace(m, " ").trim()).filter(Boolean), n = "", r = !1;
|
|
58
|
+
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("\\");
|
|
59
|
+
return n.trim();
|
|
60
|
+
}, v = i((i = {}) => {
|
|
61
|
+
let a = i.tags || s, o = i.transform || _, u = e(i.include || c, i.exclude || l), d = "", f = "";
|
|
58
62
|
return {
|
|
59
63
|
name: "compress-shader-literals",
|
|
60
64
|
enforce: "pre",
|
|
61
65
|
transform(e, t) {
|
|
62
66
|
if (!u(t) || !a.some((t) => e.includes(t))) return null;
|
|
63
|
-
let n =
|
|
67
|
+
let n = g(e, a);
|
|
64
68
|
if (n.length === 0) return null;
|
|
65
69
|
i.debug && console.log(`[compress-shader-literals] ${t}: ${n.length} literal(s) — ${n.map((e) => e.tag).join(", ")}`);
|
|
66
70
|
let s = new r(e), c = !1;
|
|
67
71
|
for (let e of n) {
|
|
68
72
|
let t = o(e.value);
|
|
69
|
-
e.value !== t && (s.overwrite(e.start, e.end, `\`${t}\``), c = !0), i.outputRatio && (d += e.value,
|
|
73
|
+
e.value !== t && (s.overwrite(e.start, e.end, `\`${t}\``), c = !0), i.outputRatio && (d += e.value, f += t);
|
|
70
74
|
}
|
|
71
75
|
return c ? {
|
|
72
76
|
code: s.toString(),
|
|
@@ -77,9 +81,9 @@ var s = [
|
|
|
77
81
|
} : null;
|
|
78
82
|
},
|
|
79
83
|
buildEnd() {
|
|
80
|
-
i.outputRatio && d && t(n.text(d), n.text(
|
|
84
|
+
i.outputRatio && d && t(n.text(d), n.text(f)).print();
|
|
81
85
|
}
|
|
82
86
|
};
|
|
83
87
|
});
|
|
84
88
|
//#endregion
|
|
85
|
-
export {
|
|
89
|
+
export { v as compressShaderLiterals, g as extractShaderLiterals, _ as minifyShader };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compress-shader-literals",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Minify GLSL/WGSL shaders in your JS/TS at build time. Drop-in plugin for Vite, Rollup, webpack, esbuild, Rspack, Rolldown & Farm.",
|
|
6
6
|
"keywords": [
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
"test:build": "bun run build && node tests/build-smoke.js",
|
|
64
64
|
"test:validate": "cd tests && bun install && node validate.js",
|
|
65
65
|
"test:e2e": "cd tests && bun install && node e2e.js",
|
|
66
|
+
"test:dump": "cd tests && bun install && node dump-chunks.js",
|
|
67
|
+
"tests:next": "cd tests && bun install && node experimental.js",
|
|
66
68
|
"format": "prettier --write .",
|
|
67
69
|
"format:check": "prettier --check .",
|
|
68
70
|
"npm:deploy": "bash ./scripts/publish-npm.sh",
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"@babel/parser": "^8.0.0",
|
|
74
76
|
"@babel/traverse": "^8.0.0",
|
|
75
77
|
"@rollup/pluginutils": "^5.4.0",
|
|
76
|
-
"byte-snap": "^1.0
|
|
78
|
+
"byte-snap": "^1.1.0",
|
|
77
79
|
"magic-string": "^0.30.21",
|
|
78
80
|
"unplugin": "^3.0.0"
|
|
79
81
|
},
|