Next.js Discord

Discord Forum

Setting CDN URL for assets with webpack

Unanswered
Western Gull posted this in #help-forum
Open in Discord
Avatar
Western GullOP
I’m updating an old Next.js app to Next 13, which entails updating the built-in Webpack config. My config includes a rule to rewrite the URLs of static assets so that they can be served from a CDN (the deployed app runs on Netlify, but I’d prefer to keep static assets on my own CDN). The rule in question looks like this:

config.module.rules.push({
  test: /\.(ico|icns|png|jpg|jpeg|svg|gif|ttf|woff|mp3)$/,
  type: 'asset/resource',
  generator: {
    emit: !isServer,
    filename: `static/[name].[hash:8][ext]`,
    publicPath: (url) => `${cdnHost}/_next/static/${url}`,
  },
});


The issue is that the generated URL once deployed looks like:

https://cdn.hostname.com/_next/static/[object Object]static/favicon.e72aff1c.ico


Can anyone explain why I’m getting this [object Object] in the middle of my URL?

0 Replies