From 9c3995cced298b11823e03c3313bf1bfa1949323 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 2 Feb 2023 17:11:11 -0800 Subject: [PATCH 01/10] Add docs for turbopack experimental fields --- .../next.config.js/resolve-alias.md | 28 +++++++++++++ .../next.config.js/turbopack-loaders.md | 41 +++++++++++++++++++ docs/manifest.json | 8 ++++ 3 files changed, 77 insertions(+) create mode 100644 docs/api-reference/next.config.js/resolve-alias.md create mode 100644 docs/api-reference/next.config.js/turbopack-loaders.md diff --git a/docs/api-reference/next.config.js/resolve-alias.md b/docs/api-reference/next.config.js/resolve-alias.md new file mode 100644 index 0000000000000..ff9ee4982f172 --- /dev/null +++ b/docs/api-reference/next.config.js/resolve-alias.md @@ -0,0 +1,28 @@ +--- +description: Configure Next.js with Turbopack to alias module resolution +--- + +# Resolve Alias (`next --turbo` only) + +Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to Webpack's [`resolve.alias`](https://Webpack.js.org/configuration/resolve/#resolvealias) configuration. + +> **Warning**: This feature is experimental and will only work with `next --turbo` + +To configure resolve aliases, map imported patterns to their new destination in `next.config.js`: + +```js +module.exports = { + experimental: { + resolveAlias: { + foo: 'bar', + baz: { browser: 'baz/browser' }, + }, + }, +} +``` + +This aliases imports of the `foo` package to the `bar` package. In other words, `import 'foo'` will result in loading the `bar` module instead of `foo`. + +Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `baz` module will be aliased to `baz/browser` when Turbopack targets browser environments. + +For more information and guidance for how to migrate your app to Turbopack from Webpack, see [Turbopack's documentation on Webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/api-reference/next.config.js/turbopack-loaders.md b/docs/api-reference/next.config.js/turbopack-loaders.md new file mode 100644 index 0000000000000..1c45fa8f4653c --- /dev/null +++ b/docs/api-reference/next.config.js/turbopack-loaders.md @@ -0,0 +1,41 @@ +--- +description: Configure Next.js with Turbopack to load Webpack loaders +--- + +# Turbopack Loaders (`next --turbo` only) + +Currently, Turbopack supports a subset of Webpack's loader API, allowing you to use some Webpack loaders to transform code in Turbopack. + +> **Warning**: This feature is experimental and will only work with `next --turbo` + +To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`: + +```js +module.exports = { + experimental: { + turbopackLoaders: { + '.mdx': [ + { + loader: '@mdx-js/loader', + options: { + format: 'mdx', + }, + }, + ], + '.foo': 'my-foo-loader', + }, + }, +} +``` + +Then, given the above configuration, you can use transformed code from your app: + +```js +import MyDoc from './my-doc.mdx' + +export default function Home() { + return +} +``` + +For more information and guidance for how to migrate your app to Turbopack from Webpack, see [Turbopack's documentation on Webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/manifest.json b/docs/manifest.json index 76405ea62a0eb..e672334bc7e8a 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -571,6 +571,14 @@ { "title": "Build indicator", "path": "/docs/api-reference/next.config.js/build-indicator.md" + }, + { + "title": "Turbopack Loaders", + "path": "/docs/api-reference/next.config.js/turbopack-loaders.md" + }, + { + "title": "Resolve Alias", + "path": "/docs/api-reference/next.config.js/resolve-alias.md" } ] } From 7639b5376bffc6373b2477908a6dbc2f11ede035 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Fri, 3 Feb 2023 08:23:56 -0800 Subject: [PATCH 02/10] Add typings and schema for turbopack experimental options --- packages/next/src/server/config-schema.ts | 3 +++ packages/next/src/server/config-shared.ts | 32 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index 82965fc1206e0..2229e46a36327 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -438,6 +438,9 @@ const configSchema = { mdxRs: { type: 'boolean', }, + resolveAlias: { + type: 'object', + }, turbopackLoaders: { type: 'object', }, diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 824c9d06bbe10..377482b92304c 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -46,6 +46,21 @@ export interface TypeScriptConfig { tsconfigPath?: string } +type JSONValue = + | string + | number + | boolean + | JSONValue[] + | { [k: string]: JSONValue } + +type TurbopackLoaderItem = + | string + | { + loader: string + // At the moment, Turbopack options must be JSON-serializable, so restrict values. + options: Record + } + export interface WebpackConfigContext { /** Next.js root directory */ dir: string @@ -157,8 +172,21 @@ export interface ExperimentalConfig { webVitalsAttribution?: Array - // webpack loaders to use when running turbopack - turbopackLoaders?: Record + /** + * (`next --turbo` only) A mapping of aliased imports to modules to load in their place. + * + * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) + */ + resolveAlias?: { + [k: string]: string | string[] | Record + } + + /** + * (`next --turbo` only) A list of webpack loaders to apply when running with Turbopack. + * + * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/turbopack-loaders) + */ + turbopackLoaders?: Record turbotrace?: { logLevel?: From 3f8587c5a3a41b34b202d3b877d4a3c98bf3223e Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Fri, 3 Feb 2023 08:52:56 -0800 Subject: [PATCH 03/10] fixup! Add typings and schema for turbopack experimental options --- packages/next/src/server/config-shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 6cdc0d1a24ccb..2644ceb97c96b 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -175,7 +175,7 @@ export interface ExperimentalConfig { /** * (`next --turbo` only) A mapping of aliased imports to modules to load in their place. * - * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) + * @see [Resolve Alias](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) */ resolveAlias?: { [k: string]: string | string[] | Record From 3b47752019ea8ab2149ecc5b74e4904a19140065 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Fri, 3 Feb 2023 08:56:18 -0800 Subject: [PATCH 04/10] fixup! Add typings and schema for turbopack experimental options --- packages/next/src/server/config-shared.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 2644ceb97c96b..f31767deeb7ce 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -177,9 +177,10 @@ export interface ExperimentalConfig { * * @see [Resolve Alias](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) */ - resolveAlias?: { - [k: string]: string | string[] | Record - } + resolveAlias?: Record< + string, + string | string[] | Record + > /** * (`next --turbo` only) A list of webpack loaders to apply when running with Turbopack. From 4a356518f09ce133ba7b624d5d9453b6039ded6a Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 6 Feb 2023 09:18:01 -0800 Subject: [PATCH 05/10] Feedback --- .../next.config.js/turbopack-loaders.md | 16 ++++++++-------- ...solve-alias.md => turbopack-resolve-alias.md} | 16 ++++++++-------- docs/manifest.json | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) rename docs/api-reference/next.config.js/{resolve-alias.md => turbopack-resolve-alias.md} (56%) diff --git a/docs/api-reference/next.config.js/turbopack-loaders.md b/docs/api-reference/next.config.js/turbopack-loaders.md index 1c45fa8f4653c..5298d269fda3f 100644 --- a/docs/api-reference/next.config.js/turbopack-loaders.md +++ b/docs/api-reference/next.config.js/turbopack-loaders.md @@ -1,28 +1,28 @@ --- -description: Configure Next.js with Turbopack to load Webpack loaders +description: Configure Next.js with Turbopack to load webpack loaders --- # Turbopack Loaders (`next --turbo` only) -Currently, Turbopack supports a subset of Webpack's loader API, allowing you to use some Webpack loaders to transform code in Turbopack. +Currently, Turbopack supports a subset of webpack's loader API, allowing you to use some webpack loaders to transform code in Turbopack. -> **Warning**: This feature is experimental and will only work with `next --turbo` +> **Warning**: This feature is experimental and will only work with `next --turbo`. -To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`: +To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`, mapping file extensions to a list of loaders: ```js module.exports = { experimental: { turbopackLoaders: { - '.mdx': [ + '.md': [ { loader: '@mdx-js/loader', options: { - format: 'mdx', + format: 'md', }, }, ], - '.foo': 'my-foo-loader', + '.mdx': '@mdx-js/loader', }, }, } @@ -38,4 +38,4 @@ export default function Home() { } ``` -For more information and guidance for how to migrate your app to Turbopack from Webpack, see [Turbopack's documentation on Webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). +For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/api-reference/next.config.js/resolve-alias.md b/docs/api-reference/next.config.js/turbopack-resolve-alias.md similarity index 56% rename from docs/api-reference/next.config.js/resolve-alias.md rename to docs/api-reference/next.config.js/turbopack-resolve-alias.md index ff9ee4982f172..2660df666fa99 100644 --- a/docs/api-reference/next.config.js/resolve-alias.md +++ b/docs/api-reference/next.config.js/turbopack-resolve-alias.md @@ -4,25 +4,25 @@ description: Configure Next.js with Turbopack to alias module resolution # Resolve Alias (`next --turbo` only) -Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to Webpack's [`resolve.alias`](https://Webpack.js.org/configuration/resolve/#resolvealias) configuration. +Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) configuration. -> **Warning**: This feature is experimental and will only work with `next --turbo` +> **Warning**: This feature is experimental and will only work with `next --turbo`. To configure resolve aliases, map imported patterns to their new destination in `next.config.js`: ```js module.exports = { experimental: { - resolveAlias: { - foo: 'bar', - baz: { browser: 'baz/browser' }, + turbopackResolveAlias: { + underscore: 'lodash', + mocha: { browser: 'mocha/browser-entry.js' }, }, }, } ``` -This aliases imports of the `foo` package to the `bar` package. In other words, `import 'foo'` will result in loading the `bar` module instead of `foo`. +This aliases imports of the `underscore` package to the `lodash` package. In other words, `import underscore from 'underscore'` will load the `lodash` module instead of `underscore`. -Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `baz` module will be aliased to `baz/browser` when Turbopack targets browser environments. +Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `mocha` module will be aliased to `mocha/browser-entry.js` when Turbopack targets browser environments. -For more information and guidance for how to migrate your app to Turbopack from Webpack, see [Turbopack's documentation on Webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). +For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/manifest.json b/docs/manifest.json index e672334bc7e8a..485ad68834a0a 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -578,7 +578,7 @@ }, { "title": "Resolve Alias", - "path": "/docs/api-reference/next.config.js/resolve-alias.md" + "path": "/docs/api-reference/next.config.js/turbopack-resolve-alias.md" } ] } From d86fe71bfca57fbb77df3a09096598713a7ea8d0 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 6 Feb 2023 09:23:28 -0800 Subject: [PATCH 06/10] fixup! Merge remote-tracking branch 'upstream/canary' into wbinnssmith/turbopack-loaders-docs --- docs/api-reference/next.config.js/turbopack-loaders.md | 2 +- docs/api-reference/next.config.js/turbopack-resolve-alias.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api-reference/next.config.js/turbopack-loaders.md b/docs/api-reference/next.config.js/turbopack-loaders.md index 5298d269fda3f..f8dfb11451f23 100644 --- a/docs/api-reference/next.config.js/turbopack-loaders.md +++ b/docs/api-reference/next.config.js/turbopack-loaders.md @@ -2,7 +2,7 @@ description: Configure Next.js with Turbopack to load webpack loaders --- -# Turbopack Loaders (`next --turbo` only) +# Turbopack Loaders Currently, Turbopack supports a subset of webpack's loader API, allowing you to use some webpack loaders to transform code in Turbopack. diff --git a/docs/api-reference/next.config.js/turbopack-resolve-alias.md b/docs/api-reference/next.config.js/turbopack-resolve-alias.md index 2660df666fa99..456f0650e88b9 100644 --- a/docs/api-reference/next.config.js/turbopack-resolve-alias.md +++ b/docs/api-reference/next.config.js/turbopack-resolve-alias.md @@ -2,7 +2,7 @@ description: Configure Next.js with Turbopack to alias module resolution --- -# Resolve Alias (`next --turbo` only) +# Turbopack Resolve Alias Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) configuration. From dec6b40a6af89fc034cef80706e0a95730dfa467 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Tue, 7 Feb 2023 17:20:24 -0800 Subject: [PATCH 07/10] Feedback --- .../next.config.js/turbopack-loaders.md | 41 ----------- .../next.config.js/turbopack-resolve-alias.md | 28 -------- .../api-reference/next.config.js/turbopack.md | 70 +++++++++++++++++++ docs/manifest.json | 8 +-- 4 files changed, 72 insertions(+), 75 deletions(-) delete mode 100644 docs/api-reference/next.config.js/turbopack-loaders.md delete mode 100644 docs/api-reference/next.config.js/turbopack-resolve-alias.md create mode 100644 docs/api-reference/next.config.js/turbopack.md diff --git a/docs/api-reference/next.config.js/turbopack-loaders.md b/docs/api-reference/next.config.js/turbopack-loaders.md deleted file mode 100644 index f8dfb11451f23..0000000000000 --- a/docs/api-reference/next.config.js/turbopack-loaders.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -description: Configure Next.js with Turbopack to load webpack loaders ---- - -# Turbopack Loaders - -Currently, Turbopack supports a subset of webpack's loader API, allowing you to use some webpack loaders to transform code in Turbopack. - -> **Warning**: This feature is experimental and will only work with `next --turbo`. - -To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`, mapping file extensions to a list of loaders: - -```js -module.exports = { - experimental: { - turbopackLoaders: { - '.md': [ - { - loader: '@mdx-js/loader', - options: { - format: 'md', - }, - }, - ], - '.mdx': '@mdx-js/loader', - }, - }, -} -``` - -Then, given the above configuration, you can use transformed code from your app: - -```js -import MyDoc from './my-doc.mdx' - -export default function Home() { - return -} -``` - -For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/api-reference/next.config.js/turbopack-resolve-alias.md b/docs/api-reference/next.config.js/turbopack-resolve-alias.md deleted file mode 100644 index 456f0650e88b9..0000000000000 --- a/docs/api-reference/next.config.js/turbopack-resolve-alias.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -description: Configure Next.js with Turbopack to alias module resolution ---- - -# Turbopack Resolve Alias - -Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) configuration. - -> **Warning**: This feature is experimental and will only work with `next --turbo`. - -To configure resolve aliases, map imported patterns to their new destination in `next.config.js`: - -```js -module.exports = { - experimental: { - turbopackResolveAlias: { - underscore: 'lodash', - mocha: { browser: 'mocha/browser-entry.js' }, - }, - }, -} -``` - -This aliases imports of the `underscore` package to the `lodash` package. In other words, `import underscore from 'underscore'` will load the `lodash` module instead of `underscore`. - -Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `mocha` module will be aliased to `mocha/browser-entry.js` when Turbopack targets browser environments. - -For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/api-reference/next.config.js/turbopack.md b/docs/api-reference/next.config.js/turbopack.md new file mode 100644 index 0000000000000..b1c41e1d6b0e9 --- /dev/null +++ b/docs/api-reference/next.config.js/turbopack.md @@ -0,0 +1,70 @@ +--- +description: Configure Next.js with Turbopack to load webpack loaders +--- + +# Turbopack-specific options + +> **Warning**: These features are experimental and will only work with `next --turbo`. + +## webpack loaders + +Currently, Turbopack supports a subset of webpack's loader API, allowing you to use some webpack loaders to transform code in Turbopack. + +To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`, mapping file extensions to a list of loaders: + +```js +module.exports = { + experimental: { + turbopack: { + loaders: { + // Option format + '.md': [ + { + loader: '@mdx-js/loader', + options: { + format: 'md', + }, + }, + ], + // Option-less format + '.mdx': '@mdx-js/loader', + }, + }, + }, +} +``` + +Then, given the above configuration, you can use transformed code from your app: + +```js +import MyDoc from './my-doc.mdx' + +export default function Home() { + return +} +``` + +## Resolve Alias + +Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) configuration. + +To configure resolve aliases, map imported patterns to their new destination in `next.config.js`: + +```js +module.exports = { + experimental: { + turbopack: { + resolveAlias: { + underscore: 'lodash', + mocha: { browser: 'mocha/browser-entry.js' }, + }, + }, + }, +} +``` + +This aliases imports of the `underscore` package to the `lodash` package. In other words, `import underscore from 'underscore'` will load the `lodash` module instead of `underscore`. + +Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `mocha` module will be aliased to `mocha/browser-entry.js` when Turbopack targets browser environments. + +For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack). diff --git a/docs/manifest.json b/docs/manifest.json index 485ad68834a0a..581c53ced2236 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -573,12 +573,8 @@ "path": "/docs/api-reference/next.config.js/build-indicator.md" }, { - "title": "Turbopack Loaders", - "path": "/docs/api-reference/next.config.js/turbopack-loaders.md" - }, - { - "title": "Resolve Alias", - "path": "/docs/api-reference/next.config.js/turbopack-resolve-alias.md" + "title": "Turbopack-specific options", + "path": "/docs/api-reference/next.config.js/turbopack.md" } ] } From b8aef83e790794c356af274428ad4880976a7cc4 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Tue, 7 Feb 2023 17:22:02 -0800 Subject: [PATCH 08/10] fixup! Feedback --- docs/api-reference/next.config.js/turbopack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-reference/next.config.js/turbopack.md b/docs/api-reference/next.config.js/turbopack.md index b1c41e1d6b0e9..4975da3dd19be 100644 --- a/docs/api-reference/next.config.js/turbopack.md +++ b/docs/api-reference/next.config.js/turbopack.md @@ -2,7 +2,7 @@ description: Configure Next.js with Turbopack to load webpack loaders --- -# Turbopack-specific options +# Turbopack-specific options (experimental) > **Warning**: These features are experimental and will only work with `next --turbo`. From ea3ecba1ceadd72cc0315bcc7d505c4b9f3f8a05 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 8 Feb 2023 10:25:18 -0800 Subject: [PATCH 09/10] turbopack -> turbo --- .../api-reference/next.config.js/turbopack.md | 6 +-- packages/next/src/cli/next-dev.ts | 3 +- packages/next/src/server/config-schema.ts | 14 +++++-- packages/next/src/server/config-shared.ts | 40 ++++++++++--------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/docs/api-reference/next.config.js/turbopack.md b/docs/api-reference/next.config.js/turbopack.md index 4975da3dd19be..dad882dcea556 100644 --- a/docs/api-reference/next.config.js/turbopack.md +++ b/docs/api-reference/next.config.js/turbopack.md @@ -1,5 +1,5 @@ --- -description: Configure Next.js with Turbopack to load webpack loaders +description: Configure Next.js with Turbopack-specific options --- # Turbopack-specific options (experimental) @@ -15,7 +15,7 @@ To configure loaders, add the names of the loaders you've installed and any opti ```js module.exports = { experimental: { - turbopack: { + turbo: { loaders: { // Option format '.md': [ @@ -53,7 +53,7 @@ To configure resolve aliases, map imported patterns to their new destination in ```js module.exports = { experimental: { - turbopack: { + turbo: { resolveAlias: { underscore: 'lodash', mocha: { browser: 'mocha/browser-entry.js' }, diff --git a/packages/next/src/cli/next-dev.ts b/packages/next/src/cli/next-dev.ts index a4fec4e9c18ff..9400acad3734f 100644 --- a/packages/next/src/cli/next-dev.ts +++ b/packages/next/src/cli/next-dev.ts @@ -200,9 +200,8 @@ const nextDev: CliCommand = async (argv) => { 'configFileName', 'env', 'experimental.appDir', - 'experimental.resolveAlias', 'experimental.serverComponentsExternalPackages', - 'experimental.turbopackLoaders', + 'experimental.turbo', 'images', 'pageExtensions', 'onDemandEntries', diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index fbf5801bdbb11..5c9ea4278b922 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -441,11 +441,17 @@ const configSchema = { webpackBuildWorker: { type: 'boolean', }, - resolveAlias: { - type: 'object', - }, - turbopackLoaders: { + turbo: { type: 'object', + additionalProperties: false, + properties: { + loaders: { + type: 'object', + }, + resolveAlias: { + type: 'object', + }, + }, }, turbotrace: { type: 'object', diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index f31767deeb7ce..103f4f22497e8 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -53,7 +53,7 @@ type JSONValue = | JSONValue[] | { [k: string]: JSONValue } -type TurbopackLoaderItem = +type TurboLoaderItem = | string | { loader: string @@ -61,6 +61,25 @@ type TurbopackLoaderItem = options: Record } +interface ExperimentalTurboOptions { + /** + * (`next --turbo` only) A mapping of aliased imports to modules to load in their place. + * + * @see [Resolve Alias](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) + */ + resolveAlias?: Record< + string, + string | string[] | Record + > + + /** + * (`next --turbo` only) A list of webpack loaders to apply when running with Turbopack. + * + * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/turbopack-loaders) + */ + loaders?: Record +} + export interface WebpackConfigContext { /** Next.js root directory */ dir: string @@ -172,23 +191,7 @@ export interface ExperimentalConfig { webVitalsAttribution?: Array - /** - * (`next --turbo` only) A mapping of aliased imports to modules to load in their place. - * - * @see [Resolve Alias](https://nextjs.org/docs/api-reference/next.config.js/resolve-alias) - */ - resolveAlias?: Record< - string, - string | string[] | Record - > - - /** - * (`next --turbo` only) A list of webpack loaders to apply when running with Turbopack. - * - * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/turbopack-loaders) - */ - turbopackLoaders?: Record - + turbo?: ExperimentalTurboOptions turbotrace?: { logLevel?: | 'bug' @@ -654,6 +657,7 @@ export const defaultConfig: NextConfig = { enableUndici: false, adjustFontFallbacks: false, adjustFontFallbacksWithSizeAdjust: false, + turbo: undefined, turbotrace: undefined, }, } From 5efcc22c4c9639f0726ada7f606572ab22fc73a2 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 8 Feb 2023 11:42:06 -0800 Subject: [PATCH 10/10] fixup! turbopack -> turbo --- packages/next/src/server/config-shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 103f4f22497e8..442165d030eff 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -77,7 +77,7 @@ interface ExperimentalTurboOptions { * * @see [Turbopack Loaders](https://nextjs.org/docs/api-reference/next.config.js/turbopack-loaders) */ - loaders?: Record + loaders?: Record } export interface WebpackConfigContext {