Unverified Commit 4972f230 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add support for --experimental-app-only (#45352)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

Allows you to `next build --experimental-app-only` which excludes
`pages` altogether. Useful for quickly debugging while migrating.
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 67468f98
......@@ -260,7 +260,8 @@ export default async function build(
reactProductionProfiling = false,
debugOutput = false,
runLint = true,
noMangling = false
noMangling = false,
appDirOnly = false
): Promise<void> {
try {
const nextBuildSpan = trace('next-build', undefined, {
......@@ -481,16 +482,17 @@ export default async function build(
prefixText: `${Log.prefixes.info} Creating an optimized production build`,
})
const pagesPaths = pagesDir
? await nextBuildSpan
.traceChild('collect-pages')
.traceAsyncFn(() =>
recursiveReadDir(
pagesDir,
new RegExp(`\\.(?:${config.pageExtensions.join('|')})$`)
const pagesPaths =
!appDirOnly && pagesDir
? await nextBuildSpan
.traceChild('collect-pages')
.traceAsyncFn(() =>
recursiveReadDir(
pagesDir,
new RegExp(`\\.(?:${config.pageExtensions.join('|')})$`)
)
)
)
: []
: []
let appPaths: string[] | undefined
......
......@@ -16,6 +16,7 @@ const nextBuild: CliCommand = (argv) => {
'--debug': Boolean,
'--no-lint': Boolean,
'--no-mangling': Boolean,
'--experimental-app-only': Boolean,
// Aliases
'-h': '--help',
'-d': '--debug',
......@@ -43,9 +44,10 @@ const nextBuild: CliCommand = (argv) => {
If no directory is provided, the current directory will be used.
Options
--profile Can be used to enable React Production Profiling
--no-lint Disable linting
--no-mangling Disable mangling
--profile Can be used to enable React Production Profiling
--no-lint Disable linting
--no-mangling Disable mangling
--experimental-app-only Only build 'app' routes
`,
0
)
......@@ -74,7 +76,8 @@ const nextBuild: CliCommand = (argv) => {
args['--profile'],
args['--debug'] || process.env.NEXT_DEBUG_BUILD,
!args['--no-lint'],
args['--no-mangling']
args['--no-mangling'],
args['--experimental-app-only']
).catch((err) => {
console.error('')
if (
......
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'app-only-flag',
{
files: __dirname,
buildCommand: 'pnpm next build --experimental-app-only',
},
({ next }) => {
it('should serve app route', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
})
it('should not serve about route', async () => {
const res = await next.fetch('/about')
expect(res.status).toBe(404)
})
}
)
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
module.exports = {
experimental: { appDir: true },
}
export default function About() {
return <h1>About</h1>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment