Skip to content

Commit

Permalink
feat: use new jsx transform (#192)
Browse files Browse the repository at this point in the history
This updates the @babel/preset-react configuration to use the new JSX transform, which no longer requires React to be imported into source files.

It also updates our eslint-config to no longer require that React be imported into source files as well.

This works because our babel (7.9.0+) and react (16.14.0+) versions are high enough that they can take advantage of the new JSX transform.

BREAKING CHANGE: Note that this means this version of frontend-build has a new peer dependency on react > 16.14.0, to ensure that it has the new JSX transform available.
  • Loading branch information
davidjoy authored Jul 21, 2021
1 parent 33cab17 commit c905398
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage/*
dist/
node_modules/
__mocks__/
__snapshots__/
6 changes: 5 additions & 1 deletion config/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-react',
[
'@babel/preset-react', {
runtime: 'automatic',
},
],
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
"react": "^16.14.0",
"react-dom": "^16.14.0"
},
"devDependencies": {
"react-test-renderer": "16.13.1"
Expand Down
2 changes: 0 additions & 2 deletions example/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import appleUrl, { ReactComponent as Apple } from './apple.svg';
import appleImg from './apple.jpg';

Expand Down
1 change: 0 additions & 1 deletion example/src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable global-require */
import React from 'react';
import renderer from 'react-test-renderer';
import App from './App';

Expand Down
1 change: 0 additions & 1 deletion example/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/preset-env": "7.10.4",
"@babel/preset-react": "7.10.4",
"@edx/eslint-config": "1.1.6",
"@edx/eslint-config": "1.2.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.0-rc.2",
"@svgr/webpack": "5.5.0",
"autoprefixer": "10.2.6",
Expand Down Expand Up @@ -81,5 +81,8 @@
"devDependencies": {
"@commitlint/cli": "11.0.0",
"@commitlint/config-angular": "11.0.0"
},
"peerDependencies": {
"react": "^16.14.0 || ^17.0.0"
}
}

0 comments on commit c905398

Please sign in to comment.