Skip to content

Commit 5218eb2

Browse files
committed
refactor: Switch to automatic runtime JSX transform (#1725)
* refactor: Switch over to automatic runtime transform for JSX * test: Removing `h` imports from test suite * docs: Adding changeset
1 parent 0f62649 commit 5218eb2

File tree

25 files changed

+20
-39
lines changed

25 files changed

+20
-39
lines changed

.changeset/metal-roses-flash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'preact-cli': major
3+
---
4+
5+
Changes the JSX transform from 'classic' to the newer 'automatic'
6+
7+
Users will no longer need to add `import { h } from 'preact'` in their components; it will be done automatically for them.

jsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"noEmit": true,
88
"resolveJsonModule": true,
99
"allowSyntheticDefaultImports": true,
10-
"jsx": "react",
11-
"jsxFactory": "h",
12-
"jsxFragmentFactory": "Fragment"
10+
"jsx": "preserve",
11+
"jsxFactory": "preact.h",
12+
"jsxFragmentFactory": "preact.Fragment"
1313
},
1414
"include": ["packages/**/*"]
1515
}

packages/cli/src/lib/babel-config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ module.exports = function (env) {
3131
require.resolve('babel-plugin-macros'),
3232
[
3333
require.resolve('@babel/plugin-transform-react-jsx'),
34-
{ pragma: 'h', pragmaFrag: 'Fragment' },
34+
{ runtime: 'automatic', importSource: 'preact' },
3535
],
3636
].filter(Boolean),
3737
overrides: [
3838
// Transforms to apply only to first-party code:
3939
{
4040
exclude: '**/node_modules/**',
41-
presets: [
42-
[require.resolve('@babel/preset-typescript'), { jsxPragma: 'h' }],
43-
],
41+
presets: [require.resolve('@babel/preset-typescript')],
4442
plugins: [
4543
!isProd && refresh && require.resolve('react-refresh/babel'),
4644
].filter(Boolean),

packages/cli/src/lib/webpack/webpack-base-config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ module.exports = function createBaseConfig(env) {
282282
}
283283
)
284284
),
285-
new webpack.ProvidePlugin({
286-
h: ['preact', 'h'],
287-
Fragment: ['preact', 'Fragment'],
288-
}),
289285
// Fix for https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
290286
new RemoveEmptyScriptsPlugin(),
291287
new MiniCssExtractPlugin({
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { h } from 'preact';
2-
31
import './style.css';
42

53
export default () => <h1>Test CSS inlining</h1>;

packages/cli/tests/subjects/css-modules/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { h } from 'preact';
2-
31
import './style.css';
42
import styles from './style.module.css';
53

packages/cli/tests/subjects/css-sass/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { h } from 'preact';
2-
31
import './style.sass';
42
import './style.scss';
53
import sassStyles from './style.module.sass';

packages/cli/tests/subjects/custom-babelrc/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, Component } from 'preact';
1+
import { Component } from 'preact';
22

33
const delay = t => new Promise(r => setTimeout(r, t));
44

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import { h } from 'preact';
2-
31
export default () => <h2>This is an app with custom template</h2>;
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import { h } from 'preact';
2-
31
export default () => <h2>This is an app with custom webpack config</h2>;

0 commit comments

Comments
 (0)