Skip to content

Commit

Permalink
docs: update webpack docs to reflect latest next.js api (#5680)
Browse files Browse the repository at this point in the history
### Description

Updates docs to reflect changes in
https://github.com/vercel/next.js/pull/49535/files

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions
QA "Customizing Turbopack" Docs

---------

Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
  • Loading branch information
willwill96 and wbinnssmith authored Aug 25, 2023
1 parent 1af6e13 commit 9774e29
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docs/pages/pack/docs/features/customizing-turbopack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ If you need loader support beyond what's built in, many webpack loaders already
- Only loaders that return JavaScript code are supported. Loaders that transform files like stylesheets or images are not currently supported.
- Options passed to webpack loaders must be plain JavaScript primitives, objects, and arrays. For example, it's not possible to pass `require()`d plugin modules as option values.

As of Next 13.2, configuring webpack loaders is possible for Next.js apps through an experimental option in `next.config.js`. `turbo.loaders` can be set as a mapping of file extensions to a list of package names or `{loader, options}` pairs:
As of Next 13.2, configuring webpack loaders is possible for Next.js apps through an experimental option in `next.config.js`. `turbo.rules` can be set as a mapping of file globs to a list of package names or `{loader, options}` pairs:

```js filename="next.config.js"
module.exports = {
experimental: {
turbo: {
loaders: {
rules: {
// Option format
'.md': [
'*.md': [
{
loader: '@mdx-js/loader',
options: {
Expand All @@ -38,13 +38,17 @@ module.exports = {
},
],
// Option-less format
'.mdx': ['@mdx-js/loader'],
'*.mdx': ['@mdx-js/loader'],
},
},
},
}
```

<Callout type="info">
Note: Prior to Next.js version 13.4.4, `experimental.turbo.rules` was named `experimental.turbo.loaders` and only accepted file extensions like `.mdx` instead of `*.mdx`.
</Callout>

If you need to pass something like the result of importing an external package as a loader option, it's possible to wrap the webpack loader with your own, specifying options there. **This is an interim solution and should not be necessary in the future.** This loader wraps `@mdx-js/loader` and configures the `rehypePrism` rehype plugin:

```js filename="my-mdx-loader.js"
Expand All @@ -70,8 +74,8 @@ Then, configure Next.js to load the wrapper loader:
module.exports = {
experimental: {
turbo: {
loaders: {
'.mdx': ['./my-mdx-loader'],
rules: {
'*.mdx': ['./my-mdx-loader'],
},
},
},
Expand Down

1 comment on commit 9774e29

@vercel
Copy link

@vercel vercel bot commented on 9774e29 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.