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( ...@@ -260,7 +260,8 @@ export default async function build(
reactProductionProfiling = false, reactProductionProfiling = false,
debugOutput = false, debugOutput = false,
runLint = true, runLint = true,
noMangling = false noMangling = false,
appDirOnly = false
): Promise<void> { ): Promise<void> {
try { try {
const nextBuildSpan = trace('next-build', undefined, { const nextBuildSpan = trace('next-build', undefined, {
...@@ -481,16 +482,17 @@ export default async function build( ...@@ -481,16 +482,17 @@ export default async function build(
prefixText: `${Log.prefixes.info} Creating an optimized production build`, prefixText: `${Log.prefixes.info} Creating an optimized production build`,
}) })
const pagesPaths = pagesDir const pagesPaths =
? await nextBuildSpan !appDirOnly && pagesDir
.traceChild('collect-pages') ? await nextBuildSpan
.traceAsyncFn(() => .traceChild('collect-pages')
recursiveReadDir( .traceAsyncFn(() =>
pagesDir, recursiveReadDir(
new RegExp(`\\.(?:${config.pageExtensions.join('|')})$`) pagesDir,
new RegExp(`\\.(?:${config.pageExtensions.join('|')})$`)
)
) )
) : []
: []
let appPaths: string[] | undefined let appPaths: string[] | undefined
......
...@@ -16,6 +16,7 @@ const nextBuild: CliCommand = (argv) => { ...@@ -16,6 +16,7 @@ const nextBuild: CliCommand = (argv) => {
'--debug': Boolean, '--debug': Boolean,
'--no-lint': Boolean, '--no-lint': Boolean,
'--no-mangling': Boolean, '--no-mangling': Boolean,
'--experimental-app-only': Boolean,
// Aliases // Aliases
'-h': '--help', '-h': '--help',
'-d': '--debug', '-d': '--debug',
...@@ -43,9 +44,10 @@ const nextBuild: CliCommand = (argv) => { ...@@ -43,9 +44,10 @@ const nextBuild: CliCommand = (argv) => {
If no directory is provided, the current directory will be used. If no directory is provided, the current directory will be used.
Options Options
--profile Can be used to enable React Production Profiling --profile Can be used to enable React Production Profiling
--no-lint Disable linting --no-lint Disable linting
--no-mangling Disable mangling --no-mangling Disable mangling
--experimental-app-only Only build 'app' routes
`, `,
0 0
) )
...@@ -74,7 +76,8 @@ const nextBuild: CliCommand = (argv) => { ...@@ -74,7 +76,8 @@ const nextBuild: CliCommand = (argv) => {
args['--profile'], args['--profile'],
args['--debug'] || process.env.NEXT_DEBUG_BUILD, args['--debug'] || process.env.NEXT_DEBUG_BUILD,
!args['--no-lint'], !args['--no-lint'],
args['--no-mangling'] args['--no-mangling'],
args['--experimental-app-only']
).catch((err) => { ).catch((err) => {
console.error('') console.error('')
if ( 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