0.10.1 • Published 8 months ago

@use-gpu/wgsl-loader v0.10.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@use-gpu/wgsl-loader

npm install --save @use-gpu/wgsl-loader
yarn add @use-gpu/wgsl-loader

Docs: https://usegpu.live/docs/reference-loader-@use-gpu-wgsl-loader

Loader - WGSL (webpack / node / rollup)

This is a webpack and node loader which enables easy use of @use-gpu/shader.

Usage

Node.js

For node, the included helper will use require-hacker to convert all *.wgsl files to CommonJS:

import "@use-gpu/wgsl-loader/node";

Webpack Config

For webpack, it will emit ESM or CommonJS automatically:

{
  // ...
  module: {
    rules: [
      //...
      {
        test: /\.wgsl$/i,
        use: ['@use-gpu/wgsl-loader'],
      },
    ],
  },
}

Rollup.js (alpha/experimental)

For rollup, import the plugin as:

import rollupWGSL from "@use-gpu/wgsl-loader/rollup";

Import

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.

Typescript

To allow shader imports to type check, create a wgsl-files.d.ts with:

declare module '*.wgsl' {
  type ParsedBundle = import('@use-gpu/shader').ParsedBundle;
  const __module: ParsedBundle;
  export default __module;
}

To make named imports import { x } from ... pass the type checker, you need to generate a custom .d.ts:

npm run wgsl-tsgen [--base-dir dir] [file or *.wgsl]
yarn run wgsl-tsgen [--base-dir dir] [file or *.wgsl]

Colofon

Made by Steven Wittens. Part of @use-gpu.

0.9.3

10 months ago

0.10.1

8 months ago

0.9.0

12 months ago

0.9.2

11 months ago

0.9.1

12 months ago

0.8.3

12 months ago

0.8.0

1 year ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago