Skip to content

Commit 52bb8a6

Browse files
committed
use esbuild-plugin-webgl
1 parent 7ffcd1b commit 52bb8a6

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"esbuild-plugin-rdi": "^0.0.0",
3636
"esbuild-plugin-react18": "0.2.4",
3737
"esbuild-plugin-react18-css": "^0.0.4",
38+
"esbuild-plugin-webgl": "^0.0.1",
3839
"jsdom": "^24.1.0",
3940
"react": "^18.3.1",
4041
"react-dom": "^18.3.1",

lib/src/simulator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ export const renderParticles = (canvas: HTMLCanvasElement, options?: ParticlesOp
267267
/** Set up observer to observe size changes */
268268
const observer = new ResizeObserver(entries => {
269269
const { width, height } = entries[0].contentRect;
270-
console.log({ width, height });
271270
canvas.width = width;
272271
canvas.height = height;
273272
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);

lib/tsup.config.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig, type Options } from "tsup";
33
import react18Plugin from "esbuild-plugin-react18";
44
import cssPlugin from "esbuild-plugin-react18-css";
55
import { rdiPlugin } from "esbuild-plugin-rdi";
6+
import { webglPlugin } from "esbuild-plugin-webgl";
67

78
export default defineConfig(
89
(options: Options) =>
@@ -19,30 +20,18 @@ export default defineConfig(
1920
name: "webgl",
2021
setup(build) {
2122
if (!options.watch)
22-
build.onLoad({ filter: /utils\.ts$/, namespace: "file" }, args => {
23+
build.onLoad({ filter: /simulator\.ts$/, namespace: "file" }, args => {
24+
console.log("utils ----- >", args.path);
2325
const text = fs.readFileSync(args.path, "utf8");
2426
const contents = text
25-
.replace(/if \(!gl[^}]*}/gm, "")
26-
.replace(/;\s*if \(![^;]*;/gm, "!;")
27+
.replace(/if \(!gl\.[^}]*}/gm, "")
28+
.replace(/;\s*if \(!(shader|program)[^;]*;/gm, "!;")
2729
.trim();
2830
return { contents, loader: "ts" };
2931
});
30-
// eslint-disable-next-line prefer-named-capture-group -- ok
31-
build.onLoad({ filter: /\.glsl$/, namespace: "file" }, args => {
32-
const text = fs.readFileSync(args.path, "utf8");
33-
const lines = text
34-
// remove comments
35-
.replace(/\/\*.*\*\//gm, "")
36-
// remove white spaces around =
37-
// .replace(/ = /g, "=")
38-
.split("\n")
39-
.map(line => line.trim())
40-
.filter(Boolean);
41-
const contents = `export default \`${lines[0]}\n${lines.slice(1).join("")}\``;
42-
return { contents, loader: "ts" };
43-
});
4432
},
4533
},
34+
webglPlugin(),
4635
react18Plugin({ disableJSXRequireDedup: true }),
4736
cssPlugin({ generateScopedName: "[folder]__[local]" }),
4837
rdiPlugin(),

pnpm-lock.yaml

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)