npm install --save @use-gpu/wgsl-loader
yarn add @use-gpu/wgsl-loader
Docs: https://usegpu.live/docs/reference-loader-@use-gpu-wgsl-loader
This is a JS loader which enables easy use of @use-gpu/shader
.
For webpack, it will emit ESM or CommonJS automatically:
{
// ...
module: {
rules: [
//...
{
test: /\.wgsl$/i,
use: ['@use-gpu/wgsl-loader'],
},
],
},
}
For rollup, import the plugin as:
import rollupWGSL from "@use-gpu/wgsl-loader/rollup";
For esbuild, import the plugin as:
import wgslPlugin from "@use-gpu/wgsl-loader/esbuild";
You can then do:
import shader from './shader.wgsl';
This will import a ParsedBundle
that can be used with @use-gpu/shader
's linkBundle(...)
function.
If you use a named import:
import { symbol } from './shader.wgsl';
You will get the same ParsedBundle
, but with entry
set to the imported symbol name.
To allow shader imports to type check, use the shader2ts
script from @use-gpu/shader
to emit .d.ts files, e.g. for src/
:
./node_modules/@use-gpu/shader/bin/shader2ts.js --noEmit --typeDef src
Made by Steven Wittens. Part of @use-gpu
.