Skip to content

Commit 929fb5c

Browse files
fixed dev vs build mismatch
1 parent 698abda commit 929fb5c

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite --open",
8-
"build": "vite build && cp -r scenes/ dist/"
8+
"build": "vite build && cp -r scenes/ dist/",
9+
"preview": "vite preview --port 4173 --strictPort --host"
910
},
1011
"devDependencies": {
1112
"@types/dat.gui": "^0.7.13",

src/shaders/shaders.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,16 @@ export const constants = {
4444

4545
// =================================
4646

47+
const constantPattern = /\$\{([a-zA-Z_]\w*)\}/g;
48+
4749
function evalShaderRaw(raw: string) {
48-
return eval('`' + raw.replaceAll('${', '${constants.') + '`');
50+
return raw.replace(constantPattern, (_match, key: string) => {
51+
const value = constants[key as keyof typeof constants];
52+
if (value === undefined) {
53+
throw new Error(`Unknown shader constant: ${key}`);
54+
}
55+
return String(value);
56+
});
4957
}
5058

5159
const commonSrc: string = evalShaderRaw(commonRaw);

0 commit comments

Comments
 (0)