@wgslx/wgslx-loader
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = require("path"); | ||
const wgslx_1 = require("@wgslx/wgslx"); | ||
@@ -22,9 +23,17 @@ __exportStar(require("./shader"), exports); | ||
this.getOptions(); | ||
const text = (0, wgslx_1.preprocess)(source); | ||
const token = wgslx_1.Syntax.translationUnitExtended.matchAll(text, this.resourcePath); | ||
if (token === null) { | ||
throw new Error('Failed to parse the shader source.'); | ||
} | ||
return [`const shader = {code:\`${(0, wgslx_1.postprocess)(token)}\`};`, 'module.exports = shader;'].join('\n'); | ||
const importResolver = { | ||
resolveFilePath: (baseFilePath, importPath) => { | ||
return (0, path_1.resolve)((0, path_1.dirname)(baseFilePath), importPath); | ||
}, | ||
readSource: (filePath) => { | ||
if (!this.fs.readFileSync) { | ||
throw new Error('File system is not available.'); | ||
} | ||
this.addDependency(filePath); | ||
return this.fs.readFileSync(filePath, 'utf8'); | ||
}, | ||
}; | ||
const code = (0, wgslx_1.compileWgslx)(source, this.resourcePath, { mode: 'wgslx', importResolver }); | ||
return [`const shader = {code:\`${code}\`};`, 'module.exports = shader;'].join('\n'); | ||
} | ||
exports.default = wgslxLoader; |
{ | ||
"name": "@wgslx/wgslx-loader", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Webpack loader for wgsl, wgslx, and wgsli files.", | ||
@@ -28,3 +28,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@wgslx/wgslx": "^0.0.5" | ||
"@wgslx/wgslx": "^0.0.7" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
@@ -0,3 +1,4 @@ | ||
import { resolve, dirname } from 'path'; | ||
import * as webpack from 'webpack'; | ||
import { Context, Cursor, Syntax, postprocess, preprocess } from '@wgslx/wgslx'; | ||
import { ImportResolver, compileWgslx } from '@wgslx/wgslx'; | ||
@@ -14,12 +15,18 @@ export * from './shader'; | ||
const text = preprocess(source); | ||
const token = Syntax.translationUnitExtended.matchAll(text, this.resourcePath); | ||
const importResolver: ImportResolver = { | ||
resolveFilePath: (baseFilePath: string, importPath: string) => { | ||
return resolve(dirname(baseFilePath), importPath); | ||
}, | ||
readSource: (filePath: string) => { | ||
if (!this.fs.readFileSync) { | ||
throw new Error('File system is not available.'); | ||
} | ||
if (token === null) { | ||
throw new Error('Failed to parse the shader source.'); | ||
} | ||
this.addDependency(filePath); | ||
return this.fs.readFileSync(filePath, 'utf8'); | ||
}, | ||
}; | ||
return [`const shader = {code:\`${postprocess(token)}\`};`, 'module.exports = shader;'].join( | ||
'\n' | ||
); | ||
const code = compileWgslx(source, this.resourcePath, { mode: 'wgslx', importResolver }); | ||
return [`const shader = {code:\`${code}\`};`, 'module.exports = shader;'].join('\n'); | ||
} |
12352
255
+ Added@wgslx/wgslx@0.0.7(transitive)
- Removed@wgslx/wgslx@0.0.5(transitive)
Updated@wgslx/wgslx@^0.0.7