Unverified Commit 82fe0d91 authored by Leah's avatar Leah Committed by GitHub

add next.config.js options currently supported by turbopack (#45309)

Closes: #45308
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 5f937d6e
...@@ -196,6 +196,19 @@ const nextDev: CliCommand = async (argv) => { ...@@ -196,6 +196,19 @@ const nextDev: CliCommand = async (argv) => {
port, port,
} }
const supportedTurbopackNextConfigOptions = [
'configFileName',
'env',
'experimental.appDir',
'experimental.resolveAlias',
'experimental.serverComponentsExternalPackages',
'experimental.turbopackLoaders',
'images',
'reactStrictMode',
'swcMinify',
'transpilePackages',
]
// check for babelrc, swc plugins // check for babelrc, swc plugins
async function validateNextConfig(isCustomTurbopack: boolean) { async function validateNextConfig(isCustomTurbopack: boolean) {
const { getPkgManager } = const { getPkgManager } =
...@@ -246,12 +259,10 @@ const nextDev: CliCommand = async (argv) => { ...@@ -246,12 +259,10 @@ const nextDev: CliCommand = async (argv) => {
try { try {
// these should not error // these should not error
if ( if (
configKey === 'serverComponentsExternalPackages' || // we only want the key after the dot for experimental options
configKey === 'appDir' || supportedTurbopackNextConfigOptions
configKey === 'images' || .map((key) => key.split('.').splice(-1)[0])
configKey === 'reactStrictMode' || .includes(configKey)
configKey === 'swcMinify' ||
configKey === 'configFileName'
) { ) {
return false return false
} }
...@@ -307,14 +318,7 @@ const nextDev: CliCommand = async (argv) => { ...@@ -307,14 +318,7 @@ const nextDev: CliCommand = async (argv) => {
unsupportedParts += `\n\n- Unsupported Next.js configuration option(s) (${chalk.cyan( unsupportedParts += `\n\n- Unsupported Next.js configuration option(s) (${chalk.cyan(
'next.config.js' 'next.config.js'
)})\n ${chalk.dim( )})\n ${chalk.dim(
`The only configurations options supported are:\n${[ `The only configurations options supported are:\n${supportedTurbopackNextConfigOptions
'reactStrictMode',
'experimental.appDir',
'experimental.serverComponentsExternalPackages',
'images',
'swcMinify',
'configFileName',
]
.map((name) => ` - ${chalk.cyan(name)}\n`) .map((name) => ` - ${chalk.cyan(name)}\n`)
.join('')} To use Turbopack, remove other configuration options.` .join('')} To use Turbopack, remove other configuration options.`
)} ` )} `
......
...@@ -618,6 +618,42 @@ export const defaultConfig: NextConfig = { ...@@ -618,6 +618,42 @@ export const defaultConfig: NextConfig = {
}, },
} }
export function setFontLoaderDefaults(config: NextConfig) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
require('@next/font/package.json')
const googleFontLoader = {
loader: '@next/font/google',
}
const localFontLoader = {
loader: '@next/font/local',
}
if (!config.experimental) {
config.experimental = {}
}
if (!config.experimental.fontLoaders) {
config.experimental.fontLoaders = []
}
if (
!config.experimental.fontLoaders.find(
({ loader }: any) => loader === googleFontLoader.loader
)
) {
config.experimental.fontLoaders.push(googleFontLoader)
}
if (
!config.experimental.fontLoaders.find(
({ loader }: any) => loader === localFontLoader.loader
)
) {
config.experimental.fontLoaders.push(localFontLoader)
}
} catch {}
}
setFontLoaderDefaults(defaultConfig)
export async function normalizeConfig(phase: string, config: any) { export async function normalizeConfig(phase: string, config: any) {
if (typeof config === 'function') { if (typeof config === 'function') {
config = config(phase, { defaultConfig }) config = config(phase, { defaultConfig })
......
export default function Page() {
return <p>hello world</p>
}
import { findPort, killApp, launchApp, renderViaHTTP } from 'next-test-utils'
import fs from 'fs-extra'
import { join } from 'path'
describe('turbopack unsupported features log', () => {
const appDir = join(__dirname, 'app')
it('should not warn by default', async () => {
let output = ''
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
turbo: true,
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
try {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).not.toContain(
'You are using configuration and/or tools that are not yet'
)
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally {
await killApp(app).catch(() => {})
}
})
const nextConfigPath = join(appDir, 'next.config.js')
it('should not warn with empty next.config.js', async () => {
let output = ''
await fs.writeFile(nextConfigPath, `module.exports = {}`)
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
turbo: true,
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
try {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).not.toContain(
'You are using configuration and/or tools that are not yet'
)
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally {
await killApp(app).catch(() => {})
await fs.remove(nextConfigPath)
}
})
it('should warn with next.config.js with unsupported field', async () => {
let output = ''
await fs.writeFile(
nextConfigPath,
`module.exports = {
assetPrefix: '/idk'
}`
)
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
turbo: true,
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
try {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).toContain(
'You are using configuration and/or tools that are not yet'
)
} finally {
await killApp(app).catch(() => {})
await fs.remove(nextConfigPath)
}
})
})
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