Replies: 4 comments 2 replies
-
I was tinkering with this a bit and found a solution that works with the current version of nextjs. The idea is to have the So a page named I wrote a simple function const withOnlyDev = (config) => {
if (process.env.NODE_ENV !== "development") {
return config
}
if (config instanceof RegExp) {
return new RegExp(config.source.replace('page', '(page|dev)'))
}
let res = []
config.forEach((item) => {
res.push(item)
res.push(item.replace('page', 'dev'))
})
return res
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
reactStrictMode: true,
pageExtensions: withOnlyDev(['page.js', 'page.jsx', 'page.ts', 'page.tsx', 'page.md', 'page.mdx']),
}
const withMDX = require('@next/mdx')({
extension: withOnlyDev(/\.page\.mdx?$/),
})
module.exports = withMDX(nextConfig) |
Beta Was this translation helpful? Give feedback.
-
There is another solution if you already have a very old project or if you didn't consider that such a thing might be needed during the implementation of the basic set of pages. You can create custom pages in a separate folder and, under certain env conditions, redirect them to mock data using webpack.NormalModuleReplacementPlugin. This mock data can return { notFound: true }. |
Beta Was this translation helpful? Give feedback.
-
We have something similar in our project. My solution was to redirect to 404 in |
Beta Was this translation helpful? Give feedback.
-
I made a poor man's patch for that to work in my project, you can find it in another issue. |
Beta Was this translation helpful? Give feedback.
-
We have a bunch of dev time only pages that we want to exclude from production builds. While there are some workarounds (like rendering an empty component in prod), I would rather have something that completely excludes the dev pages from the build completely.
From looking at the Next.js code, it looks like some code could be added in these two places to support such a use case:
next.js/packages/next/server/dev/next-dev-server.ts
Line 227 in 9343b67
next.js/packages/next/build/index.ts
Line 247 in 9343b67
I was imagining something like a
excludeFromProduction
property on the next config, with the value being an array of regexes.Is there any interest in accepting a change that does this? I'm happy to work on a PR.
Beta Was this translation helpful? Give feedback.
All reactions