Skip to content

Commit

Permalink
update readme with futher details on babel configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcwood committed Nov 19, 2020
1 parent e6fcbe2 commit 976029f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,29 @@ See the [Jest docs](https://jestjs.io/docs/en/configuration#transform-objectstri

### Options

To add custom configuration, such as using the Ruby on Rails runner for ERB compilation, add a configuration object to the transformer entry in the ```package.json``` using the Jest syntax. For example, to compile JavaScript in the rails environment:
To add custom configuration, such as using the Ruby on Rails runner for ERB compilation, add a configuration object to the transformer entry in the project ```package.json``` using the [Jest transformer configuration syntax](https://jestjs.io/docs/en/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object). For example, to compile in the rails environment:

```json
"transform": {
"^.+\\.erb$": [ "jest-erb-transformer", { "application": "rails" } ]
}
```

#### Babel

By default the transformer does not process its output with [Babel](https://babeljs.io/).

To perform post-processing with Babel, either configure the transformer ```babelConfig``` option as outlined in the options table below, or I have found including the ```.erb``` files in the [babel-jest](https://www.npmjs.com/package/babel-jest) transformer directly has worked in some scenarios. For example:

```json
"transform": {
"^.+\\.js(?:\\.erb)?$": "babel-jest",
"^.+\\.erb$": [ "jest-erb-transformer", { "application": "rails" } ]
}
```

#### All Options

| Key | Default Value | Description |
| :--- | :--- | :--- |
| ```"application"``` | ```"ruby"``` | Transformer is run using ```ruby``` by default, set value to ```"rails"``` to use ```bin/rails runner```. The ```"rails"``` option can be useful if the .erb files include Ruby on Rails specific environment variables such as ```Rails.application.credentails```. |
Expand Down

0 comments on commit 976029f

Please sign in to comment.