From 95291df10ecc2e1ec076db2f771e03fcd465fa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Tue, 27 Sep 2022 18:44:41 +0200 Subject: [PATCH] Include `react/jsx-dev-runtime` for dependencies optimisation when using automatic runtime [publish] --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/swc-react-refresh.ts | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 282fd84..d6546bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.3 + +Include `react/jsx-dev-runtime` for dependencies optimisation when using automatic runtime. + ## 2.0.2 Unpinned `@swc/core` to get new features (like TS instantiation expression) despite a [30mb bump of bundle size](https://github.com/swc-project/swc/issues/3899) diff --git a/package.json b/package.json index 5031adb..aa2e187 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-swc-react-refresh", "description": "Use the versatility of swc for development and the maturity of esbuild for production", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "author": "Arnaud Barré (https://github.com/ArnaudBarre)", "main": "src/swc-react-refresh.js", diff --git a/src/swc-react-refresh.ts b/src/swc-react-refresh.ts index 3a4e385..b25b3e9 100644 --- a/src/swc-react-refresh.ts +++ b/src/swc-react-refresh.ts @@ -23,7 +23,12 @@ export const swcReactRefresh = (): PluginOption => ({ define = config.esbuild.define; automaticRuntime = config.esbuild.jsx === "automatic"; } - config.esbuild = false; + return automaticRuntime + ? { + esbuild: false, + optimizeDeps: { include: ["react/jsx-dev-runtime"] }, + } + : { esbuild: false }; }, resolveId: (id) => (id === runtimePublicPath ? id : undefined), load: (id) => @@ -57,6 +62,7 @@ export const swcReactRefresh = (): PluginOption => ({ }); if ( + !automaticRuntime && result.code.includes("React.createElement") && !importReactRE.test(result.code) ) {