Skip to content

Commit dcd73dd

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 1797d9e commit dcd73dd

File tree

26 files changed

+32
-51
lines changed

26 files changed

+32
-51
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/lib/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/lib/lib/webpack/webpack-base-config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ module.exports = function createBaseConfig(env) {
287287
}
288288
)
289289
),
290-
new webpack.ProvidePlugin({
291-
h: ['preact', 'h'],
292-
Fragment: ['preact', 'Fragment'],
293-
}),
294290
// Fix for https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
295291
new RemoveEmptyScriptsPlugin(),
296292
new MiniCssExtractPlugin({

packages/cli/tests/images/build.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ exports.default = {
1313
'ssr-build/ssr-bundle.js.map': 30625,
1414
'ssr-build/asset-manifest.json': 82,
1515

16-
'bundle.86ff2.js': 21323,
17-
'bundle.86ff2.js.map': 85534,
18-
'bundle.86ff2.legacy.js': 22514,
19-
'bundle.86ff2.legacy.js.map': 106422,
16+
'bundle.3c823.js': 21323,
17+
'bundle.3c823.js.map': 85534,
18+
'bundle.3c823.legacy.js': 22514,
19+
'bundle.3c823.legacy.js.map': 106422,
2020
'bundle.a2557.css': 945,
2121
'bundle.a2557.css.map': 1758,
2222

@@ -31,17 +31,17 @@ exports.default = {
3131
'push-manifest.json': 450,
3232
'asset-manifest.json': 943,
3333

34-
'route-home.chunk.b77d6.js': 306,
35-
'route-home.chunk.b77d6.js.map': 1490,
36-
'route-home.chunk.b77d6.legacy.js': 363,
37-
'route-home.chunk.b77d6.legacy.js.map': 1752,
34+
'route-home.chunk.a00bd.js': 339,
35+
'route-home.chunk.a00bd.js.map': 1811,
36+
'route-home.chunk.a00bd.legacy.js': 394,
37+
'route-home.chunk.a00bd.legacy.js.map': 2102,
3838
'route-home.chunk.6eaee.css': 112,
3939
'route-home.chunk.6eaee.css.map': 224,
4040

41-
'route-profile.chunk.d8eb4.js': 2469,
42-
'route-profile.chunk.d8eb4.js.map': 9736,
43-
'route-profile.chunk.d8eb4.legacy.js': 2624,
44-
'route-profile.chunk.d8eb4.legacy.js.map': 12373,
41+
'route-profile.chunk.05dd0.js': 2545,
42+
'route-profile.chunk.05dd0.js.map': 10268,
43+
'route-profile.chunk.05dd0.legacy.js': 2698,
44+
'route-profile.chunk.05dd0.legacy.js.map': 12894,
4545
'route-profile.chunk.0af3e.css': 118,
4646
'route-profile.chunk.0af3e.css.map': 231,
4747
};
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>;

0 commit comments

Comments
 (0)