-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turbopack experimental fields docs and schema (#45560)
This adds: - Documentation for Turbopack experimental fields `turbopackLoaders` and `resolveAlias` to the API reference site. - Typings and schema for the above Turbopack experimental options Test Plan: - `pnpm build`, updated an example to use TypeScript for its Next.js config, and verified the config passed with matching shapes and failed with mismatching shapes.
- Loading branch information
1 parent
53c2ae8
commit d726fe3
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
description: Configure Next.js with Turbopack-specific options | ||
--- | ||
|
||
# Turbopack-specific options (experimental) | ||
|
||
> **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: { | ||
turbo: { | ||
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 <MyDoc /> | ||
} | ||
``` | ||
|
||
## 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: { | ||
turbo: { | ||
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters