Skip to content

Commit 32a1d73

Browse files
committed
Add babel configuration docs to README.
1 parent 63e11cc commit 32a1d73

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ app.prepare().then(() => {
310310
```
311311

312312
The `next` API is as follows:
313-
- `next(path: string, opts: object)` - `path` is
313+
- `next(path: string, opts: object)` - `path` is
314314
- `next(opts: object)`
315315

316316
Supported options:
@@ -396,10 +396,40 @@ In order to extend our usage of `webpack`, you can define a function that extend
396396
The following example shows how you can use [`react-svg-loader`](https://github.com/boopathi/react-svg-loader) to easily import any `.svg` file as a React component, without modification.
397397

398398
```js
399+
// This file is not going through babel transformation.
400+
// So, we write it in vanilla JS
401+
// (But you could use ES2015 features supported by your Node.js version)
402+
403+
module.exports = {
404+
webpack: (config, { dev }) => {
405+
config.module.rules.push({ test: /\.svg$/, loader: 'babel!react-svg' })
406+
407+
// Important: return the modified config
408+
return config
409+
}
410+
}
411+
```
412+
413+
### Customizing babel config
414+
415+
In order to extend our usage of `babel`, you can define a function that extends its config via `next.config.js`.
416+
417+
The following example config shows you how to use `babel-preset-stage-0` with your app.
418+
419+
```js
420+
// This file is not going through babel transformation.
421+
// So, we write it in vanilla JS
422+
// (But you could use ES2015 features supported by your Node.js version)
423+
399424
module.exports = {
400-
webpack: (cfg, { dev }) => {
401-
cfg.module.rules.push({ test: /\.svg$/, loader: 'babel!react-svg' })
402-
return cfg
425+
// config is the set of options we pass to our babel-loaders's query option
426+
babel: function (config, { dev }) {
427+
// Add the stage-0 preset.
428+
// Make sure to use 'require.resolve' otherwise we won't be able to find it.
429+
config.presets.push(require.resolve('babel-preset-stage-0'))
430+
431+
// Important: return the modified config
432+
return config
403433
}
404434
}
405435
```

0 commit comments

Comments
 (0)