From 828b9287c54c9ecd3572ffe69a4287153cff7ef9 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Tue, 18 Mar 2025 21:41:00 +1100 Subject: [PATCH] try worker-loader in next config --- examples/with-nextjs/next.config.js | 35 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/with-nextjs/next.config.js b/examples/with-nextjs/next.config.js index 701438ebf..f9e932ef0 100644 --- a/examples/with-nextjs/next.config.js +++ b/examples/with-nextjs/next.config.js @@ -1,12 +1,25 @@ -/** @type {import('next').NextConfig} */ -const nextConfig = { - distDir: "build", - typescript: { - // The ts config doesn't work with `jsx: preserve" and if updated to `react-jsx` it gets ovewritten by next js throwing ts errors hence I am ignoring build errors until this is fixed. - ignoreBuildErrors: true, - }, - // This is needed as in pages router the code for importing types throws error as its outside next js app - transpilePackages: ["../"], -}; +// next.config.js +module.exports = { + webpack(config, { isServer }) { + config.distDir = "build"; + config.typescript = { + ignoreBuildErrors: true, + }; + config.transpileModules = ["../"]; -module.exports = nextConfig; + if (!isServer) { + config.module.rules.push({ + test: /\.worker\.(js|ts)$/, + use: { + loader: "worker-loader", + options: { + // You can tweak the filename pattern here + filename: "static/chunks/[hash].worker.js", + }, + }, + }); + } + + return config; + }, +};