Standalone build assetPrefix conditional config #47553
-
SummaryTrying to set Reading, does not mention this value is static and cannot change after the build: https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix It has the example of a conditional use of const isProd = process.env.NODE_ENV === 'production'
module.exports = {
// Use the CDN in production and localhost for development.
assetPrefix: isProd ? 'https://cdn.mydomain.com' : undefined,
} This led me to believe that it's possible to change this based on another process env, say for instance a custom deployment environment: module.exports = {
// eg change via env config on when the server starts
assetPrefix: process.env.CDN_PATH,
} Can't get this to work in the production build as the Anyone know how to set the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
If you opt for 'standalone' output when building, your next.config file will be serialised into ./next/standalone/server.js. As of now, a dynamic assetPrefix would be only achievable by using a custom server. |
Beta Was this translation helpful? Give feedback.
-
Just do a little string replace on the generated server.js file. |
Beta Was this translation helpful? Give feedback.
-
Next.js official needs to support this feature as soon as possible; it is very necessary. |
Beta Was this translation helpful? Give feedback.
If you opt for 'standalone' output when building, your next.config file will be serialised into ./next/standalone/server.js. As of now, a dynamic assetPrefix would be only achievable by using a custom server.