@@ -101,99 +101,47 @@ export function plugins({
101101}
102102
103103function applyTurbopackOptions ( nextConfig : NextConfig ) : void {
104- // ⚠️ IMPORTANT: Turbopack custom loaders are NOT working in Next.js 16.0.0-beta.0
105- // Users MUST run builds with --webpack flag: `next build --webpack`
106- // Only Next.js 15 with experimental.turbo is currently supported
107- //
108- // Official Turbopack documentation:
109- // https://nextjs.org/docs/app/api-reference/next-config-js/turbopack
110- // https://github.com/vercel/next.js/blob/canary/docs/01-app/03-api-reference/05-config/01-next-config-js/turbopack.mdx
111- //
112- // Advanced condition syntax (added in Next.js 16.0.0):
113- // https://nextjs.org/docs/app/api-reference/next-config-js/turbopack#advanced-webpack-loader-conditions
114- //
115- // Boolean operators:
116- // - { all: [...] } - all conditions must be true (AND)
117- // - { any: [...] } - at least one condition must be true (OR)
118- // - { not: ... } - negation (NOT)
119- //
120- // Customizable operators:
121- // - { path: string | RegExp } - matches file path (glob or regex)
122- // - { content: RegExp } - matches file content
123- // - If path and content are in same object, acts as implicit AND
124- //
125- // Built-in conditions (strings):
126- // - 'browser' - matches client-side code
127- // - 'foreign' - matches node_modules and Next.js internals
128- // - 'development' - matches next dev
129- // - 'production' - matches next build
130- // - 'node' - matches Node.js runtime
131- // - 'edge-light' - matches Edge runtime
132- //
133- // Rules can be object or array of objects for different conditions
134- //
135- // Real-world examples from GitHub:
136- // - https://github.com/EC-WIN-24-NET/Khala/blob/main/next.config.ts
137- // - https://github.com/ShizNick84/Scalping_Alchemist_Bolt/blob/main/next.config.js
138- //
139- // Example syntax for Next.js 16 (when loaders are fixed):
140- // turbopack: {
141- // rules: {
142- // '**/*.{ts,tsx,js,jsx}': [
143- // {
144- // condition: {
145- // all: [
146- // 'browser',
147- // { not: 'foreign' },
148- // { content: /"poor man's use server"|'poor man's use server'/ }
149- // ]
150- // },
151- // loaders: [{ loader: loaderPath, options: { isServer: false, ... } }],
152- // as: '*.js' // optional: output file extension
153- // },
154- // {
155- // condition: {
156- // all: [
157- // { not: 'browser' },
158- // { not: 'foreign' },
159- // { content: /"poor man's use server"|'poor man's use server'/ }
160- // ]
161- // },
162- // loaders: [{ loader: loaderPath, options: { isServer: true, ... } }],
163- // as: '*.js'
164- // }
165- // ]
166- // }
167- // }
104+ // Configure Turbopack to apply Babel transformation to TypeScript/JavaScript files
105+ // Docs: https://nextjs.org/docs/app/api-reference/next-config-js/turbopack
168106
169107 const pagesDir = findPagesDir ( process . cwd ( ) ) ;
170108 const basePath = ( nextConfig . basePath as string ) || '/' ;
171109 const loaderPath = require . resolve ( '../dist/turbopackLoader' ) ;
172110
173- // Next.js 15 experimental.turbo.rules configuration
174111 const loaderConfig = {
175- loaders : [
176- {
177- loader : loaderPath ,
178- options : {
179- isServer : true ,
180- pagesDir,
181- isAppDir : false ,
182- basePath,
112+ browser : {
113+ as : '*.tsx' ,
114+ loaders : [
115+ {
116+ loader : loaderPath ,
117+ options : {
118+ isServer : false ,
119+ pagesDir,
120+ isAppDir : false ,
121+ basePath,
122+ } ,
183123 } ,
184- } ,
185- ] ,
124+ ] ,
125+ } ,
126+ default : {
127+ as : '*.tsx' ,
128+ loaders : [
129+ {
130+ loader : loaderPath ,
131+ options : {
132+ isServer : true ,
133+ pagesDir,
134+ isAppDir : false ,
135+ basePath,
136+ } ,
137+ } ,
138+ ] ,
139+ } ,
186140 } ;
187141
188- // Only configure experimental.turbo for Next.js 15
189- // Next.js 16 turbopack does not properly support custom loaders yet
190- nextConfig . experimental ??= { } ;
191- ( nextConfig . experimental as any ) . turbo ??= { } ;
192- ( nextConfig . experimental as any ) . turbo . rules ??= { } ;
193- ( nextConfig . experimental as any ) . turbo . rules [ '**/*.{ts,tsx,js,jsx}' ] = loaderConfig ;
194-
195- // Do NOT configure turbopack.rules for Next.js 16 - it doesn't work in beta.0
196- // Users must use --webpack flag with Next.js 16
142+ ( nextConfig as any ) . turbopack ??= { } ;
143+ ( nextConfig as any ) . turbopack . rules ??= { } ;
144+ ( nextConfig as any ) . turbopack . rules [ '**/*.{ts,tsx,js,jsx}' ] = loaderConfig ;
197145}
198146
199147// taken from https://github.com/vercel/next.js/blob/v12.1.5/packages/next/lib/find-pages-dir.ts
0 commit comments