Skip to content

Commit 8b5b830

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 68e5b7f commit 8b5b830

File tree

26 files changed

+35
-54
lines changed

26 files changed

+35
-54
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
@@ -292,10 +292,6 @@ module.exports = function createBaseConfig(env) {
292292
}
293293
)
294294
),
295-
new webpack.ProvidePlugin({
296-
h: ['preact', 'h'],
297-
Fragment: ['preact', 'Fragment'],
298-
}),
299295
// Fix for https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
300296
new RemoveEmptyScriptsPlugin(),
301297
new MiniCssExtractPlugin({

packages/cli/tests/images/build.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ exports.default = {
88
'assets/favicon.ico': 15086,
99

1010
'ssr-build/ssr-bundle.dba70.css': 1281,
11-
'ssr-build/ssr-bundle.dba70.css.map': 2081,
12-
'ssr-build/ssr-bundle.js': 10453,
13-
'ssr-build/ssr-bundle.js.map': 46403,
11+
'ssr-build/ssr-bundle.dba70.css.map': 2069,
12+
'ssr-build/ssr-bundle.js': 10863,
13+
'ssr-build/ssr-bundle.js.map': 49128,
1414
'ssr-build/asset-manifest.json': 82,
1515

16-
'bundle.12615.js': 21560,
17-
'bundle.12615.js.map': 85822,
18-
'bundle.12615.legacy.js': 22549,
19-
'bundle.12615.legacy.js.map': 106841,
16+
'bundle.79d07.js': 21560,
17+
'bundle.79d07.js.map': 85822,
18+
'bundle.79d07.legacy.js': 22549,
19+
'bundle.79d07.legacy.js.map': 106841,
2020
'bundle.354c3.css': 945,
2121
'bundle.354c3.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.f910e.js': 307,
35-
'route-home.chunk.f910e.js.map': 1516,
36-
'route-home.chunk.f910e.legacy.js': 347,
37-
'route-home.chunk.f910e.legacy.js.map': 1770,
34+
'route-home.chunk.dd4a3.js': 347,
35+
'route-home.chunk.dd4a3.js.map': 1848,
36+
'route-home.chunk.dd4a3.legacy.js': 388,
37+
'route-home.chunk.dd4a3.legacy.js.map': 2136,
3838
'route-home.chunk.6eaee.css': 112,
3939
'route-home.chunk.6eaee.css.map': 224,
4040

41-
'route-profile.chunk.ef912.js': 3106,
42-
'route-profile.chunk.ef912.js.map': 12220,
43-
'route-profile.chunk.ef912.legacy.js': 3243,
44-
'route-profile.chunk.ef912.legacy.js.map': 15558,
41+
'route-profile.chunk.0d30e.js': 3198,
42+
'route-profile.chunk.0d30e.js.map': 12743,
43+
'route-profile.chunk.0d30e.legacy.js': 3335,
44+
'route-profile.chunk.0d30e.legacy.js.map': 16137,
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)