Skip to content

Commit 295795e

Browse files
authored
docs: explain that you have to use a babel.config.js for Yarn PnP (shakacode#484)
* docs: provide a basic skeleton example on customizing the babel config * docs: mention that you have to switch to `babel.config.js` for Yarn PnP * docs: add changelog entry * docs: add language to code fence
1 parent 5778617 commit 295795e

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ _next_ branch is for v8 changes
1010
## [Unreleased]
1111
Changes since the last non-beta release.
1212

13+
### Fixed
14+
15+
- Improve documentation for using Yarn PnP [PR 484](https://github.com/shakacode/shakapacker/pull/484) by [G-Rath](https://github.com/g-rath).
16+
1317
## [v8.0.0] - May 17, 2024
1418

1519
See the [v8 Upgrade Guide](https://github.com/shakacode/shakapacker/blob/main/docs/v8_upgrade.md).

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ If `packageManager` is not set when running `shakapacker:install`, Shakapacker w
167167
168168
See [here](https://github.com/G-Rath/package_json#specifying-a-package-manager) for a list of the supported package managers and more information; note that `package_json` does not handle ensuring the manager is installed.
169169

170+
If you wish to use [Yarn PnP](https://yarnpkg.com/features/pnp) you will need to configure Babel using a `babel.config.js` file rather than via `package.json` - see [customizing Babel Config](./docs/customizing_babel_config.md) for examples on how to do this.
171+
170172
> [NOTE]
171173
>
172174
> The rest of the documentation will only reference `npm` when providing commands such as to install optional packages except in cases where

docs/customizing_babel_config.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,44 @@ The default configuration of babel is done by using `package.json` to use the fi
1414
```
1515

1616
## Customizing the Babel Config
17-
This example shows how you can create an object and apply _additional_ presets and plugins on top of the default.
1817

19-
### React Configuration
20-
To use this example file,
18+
### Basic Configuration
19+
20+
This is a very basic skeleton that you can use that includes the Shakapacker preset, and makes it easy to add new plugins and presents:
21+
22+
```js
23+
// babel.config.js
24+
module.exports = function (api) {
25+
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
26+
const resultConfig = defaultConfigFunc(api)
27+
28+
const changesOnDefault = {
29+
presets: [
30+
// put custom presets here
31+
].filter(Boolean),
32+
plugins: [
33+
// put custom plugins here
34+
].filter(Boolean),
35+
}
2136

37+
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
38+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins]
39+
40+
return resultConfig
41+
}
2242
```
43+
44+
### React Configuration
45+
46+
This shows how you can add to the above skeleton to support React - to use this, install the following dependencies:
47+
48+
```bash
2349
npm install react react-dom @babel/preset-react
2450
npm install --dev @pmmmwh/react-refresh-webpack-plugin react-refresh
2551
```
2652

53+
And then update the configuration:
54+
2755
```js
2856
// babel.config.js
2957
module.exports = function (api) {
@@ -54,7 +82,7 @@ module.exports = function (api) {
5482
}
5583

5684
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
57-
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ]
85+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins]
5886

5987
return resultConfig
6088
}

0 commit comments

Comments
 (0)