🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@wgslx/wgslx-loader

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wgslx/wgslx-loader - npm Package Compare versions

Comparing version

to
0.0.2

9

dist/index.js

@@ -21,7 +21,8 @@ "use strict";

this.getOptions();
const context = wgslx_1.Context.from(source, this.resourcePath);
const cursor = (0, wgslx_1.Cursor)(0);
const match = wgslx_1.Syntax.translationUnitExtended.match(cursor, context);
const token = wgslx_1.Syntax.translationUnitExtended.matchAll(source, this.resourcePath);
if (token === null) {
throw new Error('Failed to parse the shader source.');
}
return [
`const shader = {src:\`${match.token.toString(true)}\`};`,
`const shader = {code:\`${token.toString(true)}\`};`,
'module.exports = shader;'

@@ -28,0 +29,0 @@ ].join('\n');

export interface WgslxShader {
readonly src: string;
readonly code: string;
readonly label?: string;
readonly sourceMap?: string;
}
{
"name": "@wgslx/wgslx-loader",
"version": "0.0.1",
"version": "0.0.2",
"description": "Webpack loader for wgsl, wgslx, and wgsli files.",

@@ -29,3 +29,3 @@ "main": "dist/index.js",

"dependencies": {
"@wgslx/wgslx": "^0.0.1"
"@wgslx/wgslx": "^0.0.2"
},

@@ -32,0 +32,0 @@ "devDependencies": {

# WGSLX Loader (wgslx-loader)
Webpack loader for wgsl, wgslx, and wgsli files.
Webpack loader for wgsl, wgslx, and wgsli files. Load, validate, and minify WebGPU
shaders with ease. Planned support for including other shader files.
<https://kettanaito.com/blog/writing-custom-webpack-loader>
```ts
import { code } from './shader.wgsl';
...
const shaderModule = device.createShaderModule({ code });
```
```ts
/** Shader module. */
export interface WgslxShader {
/** Shader source. */
readonly code: string;
/** Shader label derived from the file name. */
readonly label?: string;
/** Shader source map if configured to be generated. */
readonly sourceMap?: string;
}
```
## Installation
```sh
npm install --save-dev wgslx-loader
```
## Usage
```js
module.exports = {
module: {
rules: [
{
test: /\.(wgsl[ix]?)$/,
use: 'wgslx-loader',
},
],
},
};
```

@@ -15,10 +15,12 @@ import * as webpack from 'webpack';

const context = Context.from(source, this.resourcePath);
const cursor = Cursor(0);
const token = Syntax.translationUnitExtended.matchAll(source, this.resourcePath);
const match = Syntax.translationUnitExtended.match(cursor, context);
if (token === null) {
throw new Error('Failed to parse the shader source.');
}
return [
`const shader = {src:\`${match.token.toString(true)}\`};`,
`const shader = {code:\`${token.toString(true)}\`};`,
'module.exports = shader;'
].join('\n');
}

@@ -0,3 +1,11 @@

/** Shader module. */
export interface WgslxShader {
readonly src: string;
/** Shader source. */
readonly code: string;
/** Shader label derived from the file name. */
readonly label?: string;
/** Shader source map if configured to be generated. */
readonly sourceMap?: string;
}