compress-shader-literals 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/README.md +87 -23
  2. package/package.json +9 -1
package/README.md CHANGED
@@ -1,43 +1,107 @@
1
1
  # compress-shader-literals
2
2
 
3
- Local Vite plugin that minifies GLSL and WGSL shader strings at build time.
3
+ > **Size matters.** Minify your GLSL & WGSL shader strings at build time — automatically, in any bundler.
4
4
 
5
- Strips block comments, line comments, and redundant whitespace from shader template literals. Runs as a `pre` transform so the result feeds into esbuild minification.
5
+ [![npm version](https://img.shields.io/npm/v/compress-shader-literals?color=cb3837&logo=npm)](https://www.npmjs.com/package/compress-shader-literals)
6
+ [![minzipped size](https://img.shields.io/bundlephobia/minzip/compress-shader-literals?color=success)](https://bundlephobia.com/package/compress-shader-literals)
7
+ [![npm downloads](https://img.shields.io/npm/dm/compress-shader-literals?color=success)](https://www.npmjs.com/package/compress-shader-literals)
8
+ [![license](https://img.shields.io/npm/l/compress-shader-literals?color=blue)](./LICENSE)
9
+
10
+ Your shaders ship with every comment, indent, and blank line you wrote them with. This strips all of it — block comments, line comments, redundant whitespace — from `glsl` / `wgsl` template literals, **before** your bundler minifies the rest. Smaller bundles, zero source changes, full sourcemaps.
11
+
12
+ Built on [unplugin](https://github.com/unjs/unplugin), so it runs in **Vite, Rollup, webpack, esbuild, Rspack, Rolldown & Farm** from one package.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm i -D compress-shader-literals
18
+ # or: bun add -d compress-shader-literals
19
+ ```
6
20
 
7
21
  ## Usage
8
22
 
23
+ Pick your bundler — same plugin, same options:
24
+
9
25
  ```js
10
- // vite.config.js
11
- import { compressShaderLiterals } from './compress-shader-literals/plugin.js';
26
+ import { compressShaderLiterals } from 'compress-shader-literals';
12
27
 
13
- export default {
14
- plugins: [compressShaderLiterals.vite({ outputRatio: true })],
15
- };
16
- ```
28
+ // Vite vite.config.js
29
+ export default { plugins: [compressShaderLiterals.vite({ outputRatio: true })] };
17
30
 
18
- ## Options
31
+ // Rollup rollup.config.js → compressShaderLiterals.rollup({ ... })
32
+ // webpack webpack.config.js → compressShaderLiterals.webpack({ ... })
33
+ // esbuild build script → compressShaderLiterals.esbuild({ ... })
34
+ // Rspack / Rolldown / Farm → .rspack() / .rolldown() / .farm()
35
+ ```
19
36
 
20
- | Option | Default | Description |
21
- | ------------- | ---------------------------- | ------------------------------ |
22
- | `tags` | `['glsl', 'wgsl', 'shader']` | Tag names to match |
23
- | `include` | `/\.[jt]sx?$/` | Files to process |
24
- | `exclude` | `/node_modules/`, `/dist/` | Files to skip |
25
- | `outputRatio` | `false` | Print size summary after build |
37
+ That's it. Shaders are compressed on the way through; everything else is untouched.
26
38
 
27
- ## Supported syntax
39
+ ## What it compresses
28
40
 
29
41
  ```ts
30
42
  // Tagged template literal
31
- const vert = wgsl`void main() { ... }`;
43
+ const vert = glsl`
44
+ // vertex shader ← stripped
45
+ precision highp float;
46
+ void main() { gl_Position = vec4(0.0); }
47
+ `;
32
48
 
33
- // Comment-prefixed template literal
34
- const frag = /* glsl */ `void main() { ... }`;
49
+ // Comment-prefixed template literal (great for editor syntax highlighting)
50
+ const frag = /* wgsl */ `
51
+ /* fragment */
52
+ fn main() {}
53
+ `;
35
54
  ```
36
55
 
37
- ## Test
56
+ both become a single tight line, no comments, no padding.
57
+
58
+ ## Options
59
+
60
+ | Option | Default | Description |
61
+ | ------------- | ---------------------------- | --------------------------------------- |
62
+ | `tags` | `['glsl', 'wgsl', 'shader']` | Tag names / comment markers to match |
63
+ | `include` | `[/\.[jt]sx?$/]` | Files to process |
64
+ | `exclude` | `[/node_modules/, /dist/]` | Files to skip |
65
+ | `outputRatio` | `false` | Print a bytes-saved summary after build |
66
+
67
+ With `outputRatio: true`:
38
68
 
39
- ```sh
40
- node compress-shader-literals/run-test.js
41
69
  ```
70
+ compress-shader-literals
71
+ ────────────────────────
72
+ 215.00 B → 134.00 B
73
+ saved: 81.00 B (37.67% smaller)
74
+ shaders: 1
75
+ ```
76
+
77
+ ## Real-world stats
78
+
79
+ Run against the actual shaders shipped in **[three.js](https://www.npmjs.com/package/three)**, **[ogl](https://www.npmjs.com/package/ogl)**, **[shader-park-core](https://www.npmjs.com/package/shader-park-core)**, **[curtains.js](https://www.npmjs.com/package/curtainsjs)** and more — measured by this plugin's own engine ([`tests/e2e.js`](tests/e2e.js)):
80
+
81
+ <!-- STATS:START -->
82
+
83
+ | Package | Shaders | Before | After | Saved |
84
+ | --------------------- | ------: | --------: | --------: | --------: |
85
+ | `three` | 281 | 240,772 B | 203,428 B | **15.5%** |
86
+ | `@jayf0x/fluidity-js` | 9 | 9,524 B | 7,133 B | **25.1%** |
87
+ | `ogl` | 22 | 6,109 B | 5,335 B | **12.7%** |
88
+ | `shader-park-core` | 18 | 10,794 B | 9,033 B | **16.3%** |
89
+ | `curtainsjs` | 7 | 3,406 B | 2,563 B | **24.8%** |
90
+ | **Total** | 337 | 270,605 B | 227,492 B | **15.9%** |
91
+
92
+ _337 real shaders from 5 package(s), compressed by this plugin's engine._
93
+
94
+ <!-- STATS:END -->
95
+
96
+ Free bytes off code you already ship — no source changes. Marginal per shader, but it compounds across every shader in every bundle, and at infra scale even 1% is worth shipping.
97
+
98
+ ## How it works
99
+
100
+ 1. Parses each matched file with Babel (TS/JSX aware).
101
+ 2. Finds tagged and comment-prefixed shader literals (see [What it compresses](#what-it-compresses)).
102
+ 3. Strips comments + collapses whitespace, rewriting via [`magic-string`](https://github.com/Rich-Harris/magic-string) so **sourcemaps stay intact**.
103
+ 4. Runs as a `pre` transform, so your bundler's own minifier still sees the result.
104
+
105
+ ## License
42
106
 
43
- Runs the transform against `src/core/shaders.ts` and prints bytes saved.
107
+ [MIT](./LICENSE) © jayF0x
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compress-shader-literals",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "Size matters. Minify GLSL/WGSL shader template literals at build time — universal plugin for Vite, Rollup, webpack, esbuild & more.",
6
6
  "keywords": [
@@ -11,6 +11,13 @@
11
11
  "compress",
12
12
  "webgl",
13
13
  "webgpu",
14
+ "three",
15
+ "threejs",
16
+ "ogl",
17
+ "react-three-fiber",
18
+ "shader-park",
19
+ "curtainsjs",
20
+ "shadertoy",
14
21
  "vite-plugin",
15
22
  "rollup-plugin",
16
23
  "webpack-plugin",
@@ -42,6 +49,7 @@
42
49
  "build": "bun build src/plugin.js --outdir dist --entry-naming index.js --target node --format esm --external @babel/parser --external @babel/traverse --external @rollup/pluginutils --external magic-string --external unplugin && node scripts/compress-dist.js",
43
50
  "test": "bun test",
44
51
  "test:run": "bun test",
52
+ "test:e2e": "cd tests && bun install && node e2e.js",
45
53
  "format": "prettier --write .",
46
54
  "format:check": "prettier --check .",
47
55
  "npm:deploy": "bash ./scripts/publish-npm.sh",