From 976029fd4662986835d2a7f717f63f09bc5316f2 Mon Sep 17 00:00:00 2001 From: cpcwood Date: Thu, 19 Nov 2020 13:09:17 +0000 Subject: [PATCH] update readme with futher details on babel configuration --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfac2d3..25c8a97 100755 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ 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": { @@ -51,6 +51,21 @@ To add custom configuration, such as using the Ruby on Rails runner for ERB comp } ``` +#### 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```. |