From e251d03bb608ac1a7c1dbbbcb1cf4ba172fb9ecd Mon Sep 17 00:00:00 2001 From: "yuqi.pyq" Date: Tue, 26 Sep 2023 17:22:42 +0800 Subject: [PATCH] chore: fix invalid url in vite examples --- .gitignore | 1 + examples/demos/cubemap.ts | 21 +++++++++++------- examples/demos/utils.ts | 6 ++++- .../{ => public}/glsl_wgsl_compiler_bg.wasm | Bin examples/{ => public}/images/negx.jpg | Bin examples/{ => public}/images/negy.jpg | Bin examples/{ => public}/images/negz.jpg | Bin examples/{ => public}/images/posx.jpg | Bin examples/{ => public}/images/posy.jpg | Bin examples/{ => public}/images/posz.jpg | Bin package.json | 1 + 11 files changed, 20 insertions(+), 9 deletions(-) rename examples/{ => public}/glsl_wgsl_compiler_bg.wasm (100%) rename examples/{ => public}/images/negx.jpg (100%) rename examples/{ => public}/images/negy.jpg (100%) rename examples/{ => public}/images/negz.jpg (100%) rename examples/{ => public}/images/posx.jpg (100%) rename examples/{ => public}/images/posy.jpg (100%) rename examples/{ => public}/images/posz.jpg (100%) diff --git a/.gitignore b/.gitignore index 69b3632..8dffe06 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ node_modules es lib dist +examples/dist rust/target coverage diff --git a/examples/demos/cubemap.ts b/examples/demos/cubemap.ts index a9da325..dd52a8c 100644 --- a/examples/demos/cubemap.ts +++ b/examples/demos/cubemap.ts @@ -26,6 +26,18 @@ import { cubePositionOffset, cubeUVOffset, } from '../meshes/cube'; +// @ts-ignore +import posx from '../public/images/posx.jpg'; +// @ts-ignore +import negx from '../public/images/negx.jpg'; +// @ts-ignore +import posy from '../public/images/posy.jpg'; +// @ts-ignore +import negy from '../public/images/negy.jpg'; +// @ts-ignore +import posz from '../public/images/posz.jpg'; +// @ts-ignore +import negz from '../public/images/negz.jpg'; /** * @see https://webgpu.github.io/webgpu-samples/samples/texturedCube @@ -91,14 +103,7 @@ void main() { // The order of the array layers is [+X, -X, +Y, -Y, +Z, -Z] const imageBitmaps = await Promise.all( - [ - '/images/posx.jpg', - '/images/negx.jpg', - '/images/posy.jpg', - '/images/negy.jpg', - '/images/posz.jpg', - '/images/negz.jpg', - ].map(async (src) => loadImage(src)), + [posx, negx, posy, negy, posz, negz].map(async (src) => loadImage(src)), ); const texture = device.createTexture({ diff --git a/examples/demos/utils.ts b/examples/demos/utils.ts index eff2c75..35a7c8c 100644 --- a/examples/demos/utils.ts +++ b/examples/demos/utils.ts @@ -32,8 +32,12 @@ export async function initExample( onContextLost: () => {}, onContextRestored(e) {}, }); + const shaderCompilerPath = new URL( + '../public/glsl_wgsl_compiler_bg.wasm', + import.meta.url, + ).href; const deviceContributionWebGPU = new WebGPUDeviceContribution({ - shaderCompilerPath: '/glsl_wgsl_compiler_bg.wasm', + shaderCompilerPath, }); let disposeCallback; diff --git a/examples/glsl_wgsl_compiler_bg.wasm b/examples/public/glsl_wgsl_compiler_bg.wasm similarity index 100% rename from examples/glsl_wgsl_compiler_bg.wasm rename to examples/public/glsl_wgsl_compiler_bg.wasm diff --git a/examples/images/negx.jpg b/examples/public/images/negx.jpg similarity index 100% rename from examples/images/negx.jpg rename to examples/public/images/negx.jpg diff --git a/examples/images/negy.jpg b/examples/public/images/negy.jpg similarity index 100% rename from examples/images/negy.jpg rename to examples/public/images/negy.jpg diff --git a/examples/images/negz.jpg b/examples/public/images/negz.jpg similarity index 100% rename from examples/images/negz.jpg rename to examples/public/images/negz.jpg diff --git a/examples/images/posx.jpg b/examples/public/images/posx.jpg similarity index 100% rename from examples/images/posx.jpg rename to examples/public/images/posx.jpg diff --git a/examples/images/posy.jpg b/examples/public/images/posy.jpg similarity index 100% rename from examples/images/posy.jpg rename to examples/public/images/posy.jpg diff --git a/examples/images/posz.jpg b/examples/public/images/posz.jpg similarity index 100% rename from examples/images/posz.jpg rename to examples/public/images/posz.jpg diff --git a/package.json b/package.json index 89ada78..17ce3e6 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "scripts": { "dev": "vite dev", "deploy": "vite build", + "preview": "vite preview", "build": "rollup -c", "clean": "rimraf dist", "eslint": "eslint --ext .ts,.js ./src --quiet",