Skip to content

Commit

Permalink
gchimp-web-www: fix nextjs build
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Nov 15, 2024
1 parent d76e631 commit f9f96ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
39 changes: 37 additions & 2 deletions gchimp-web/www/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,46 @@ import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
webpack(config, options) {
config.experiments = { ...config.experiments, asyncWebAssembly: true };
webpack(config, { isServer, dev }) {
config.experiments = {
...config.experiments,
asyncWebAssembly: true,
layers: true,
};

// config.output.webassemblyModuleFilename =
// isServer && !dev ? "../static/wasm/[id].wasm" : "static/wasm/[id].wasm";
if (!dev && isServer) {
config.output.webassemblyModuleFilename = "chunks/[id].wasm";
config.plugins.push(new WasmChunksFixPlugin());
}

return config;
},
outputFileTracingIncludes: {
'/api/**/*': ['./node_modules/**/*.wasm', './node_modules/**/*.proto'],
}
};

// HOLY FUCK. I AM GOING TO KILL WHOEVER GETS PAID TO DO THIS
// https://github.com/vercel/next.js/issues/29362#issuecomment-971377869
class WasmChunksFixPlugin {
apply(compiler: any) {
compiler.hooks.thisCompilation.tap("WasmChunksFixPlugin", (compilation: any) => {
compilation.hooks.processAssets.tap(
{ name: "WasmChunksFixPlugin" },
(assets: any) =>
Object.entries(assets).forEach(([pathname, source]) => {
if (!pathname.match(/\.wasm$/)) return;
compilation.deleteAsset(pathname);

const name = pathname.split("/")[1];
const info = compilation.assetsInfo.get(pathname);
compilation.emitAsset(name, source, info);
})
);
});
}
}

export default nextConfig;
2 changes: 1 addition & 1 deletion gchimp-web/www/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gchimp-web/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"gchimp-web": "file:../pkg",
"next": "15.0.3",
"next": "^15.0.3",
"react": "19.0.0-rc-66855b96-20241106",
"react-dom": "19.0.0-rc-66855b96-20241106"
},
Expand Down
8 changes: 3 additions & 5 deletions gchimp-web/www/src/programs/wave-loop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { UploadButton } from "@/components/upload-button";
export const WaveLoop = () => {
const [name, setName] = useState<string | undefined>(undefined);
const [file, setFile] = useState<File | null>(null);
const [_status, setStatus] = useState<string>("Status: Idle");
const [output, setOutput] = useState<Uint8Array<ArrayBufferLike> | null>(null);
// const [status, setStatus] = useState<string>("Status: Idle");
const [output, setOutput] = useState<Uint8Array | null>(null);

const submitButton = createRef<HTMLInputElement>();

Expand All @@ -26,7 +26,7 @@ export const WaveLoop = () => {
};

if (!file) {
setStatus("No file selected")
// setStatus("No file selected")
return;
}

Expand All @@ -45,8 +45,6 @@ export const WaveLoop = () => {

const file = e.dataTransfer.files.item(0);

console.log(e.dataTransfer.files);

if (file?.name)
setName(file?.name);

Expand Down

0 comments on commit f9f96ec

Please sign in to comment.