Skip to content

Commit

Permalink
Workaround for the issue: extract babel config out of package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dandv committed Apr 29, 2019
1 parent 50a49bc commit 376ed97
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Applying babel-jest transforms to files in the parent directory

Working, minimalistic, project structure for applying Babel transforms to files in monorepo shared libraries. The illustrated transform is converting ES201 modules into CommonJS, which is very useful until [Jest adds native support for `.mjs` files](https://github.com/facebook/jest/issues/4842).

Run `npm test` to verify that both tests pass.

## Jest issue

This repo also contains a reproduction for [Jest issue #8238](https://github.com/facebook/jest/issues/8238) (transform not applied to file in parent directory) at the initial commit, [#50a49bc](https://github.com/dandv/jest-parent-dir-transform/commit/50a49bc9187b1103b5a6299517671aa8c0795912).

The solution was to move the `babel` block from `package.json` into `babel.config.js`.
5 changes: 5 additions & 0 deletions backend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: [
'transform-es2015-modules-commonjs'
],
};
9 changes: 0 additions & 9 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,5 @@
"transform": {
"^.+\\.m?js$": "babel-jest"
}
},
"babel": {
"env": {
"test": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
}
}

0 comments on commit 376ed97

Please sign in to comment.