Skip to content

Commit

Permalink
docs: explain that you have to use a babel.config.js for Yarn PnP (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
G-Rath authored May 22, 2024
1 parent 5778617 commit 295795e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ _next_ branch is for v8 changes
## [Unreleased]
Changes since the last non-beta release.

### Fixed

- Improve documentation for using Yarn PnP [PR 484](https://github.com/shakacode/shakapacker/pull/484) by [G-Rath](https://github.com/g-rath).

## [v8.0.0] - May 17, 2024

See the [v8 Upgrade Guide](https://github.com/shakacode/shakapacker/blob/main/docs/v8_upgrade.md).
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ If `packageManager` is not set when running `shakapacker:install`, Shakapacker w
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.

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.

> [NOTE]
>
> The rest of the documentation will only reference `npm` when providing commands such as to install optional packages except in cases where
Expand Down
36 changes: 32 additions & 4 deletions docs/customizing_babel_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,44 @@ The default configuration of babel is done by using `package.json` to use the fi
```

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

### React Configuration
To use this example file,
### Basic Configuration

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:

```js
// babel.config.js
module.exports = function (api) {
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
const resultConfig = defaultConfigFunc(api)

const changesOnDefault = {
presets: [
// put custom presets here
].filter(Boolean),
plugins: [
// put custom plugins here
].filter(Boolean),
}

resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins]

return resultConfig
}
```

### React Configuration

This shows how you can add to the above skeleton to support React - to use this, install the following dependencies:

```bash
npm install react react-dom @babel/preset-react
npm install --dev @pmmmwh/react-refresh-webpack-plugin react-refresh
```

And then update the configuration:

```js
// babel.config.js
module.exports = function (api) {
Expand Down Expand Up @@ -54,7 +82,7 @@ module.exports = function (api) {
}

resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ]
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins]

return resultConfig
}
Expand Down

0 comments on commit 295795e

Please sign in to comment.