Skip to content

Commit

Permalink
Include react/jsx-dev-runtime for dependencies optimisation when us…
Browse files Browse the repository at this point in the history
…ing automatic runtime [publish]
  • Loading branch information
ArnaudBarre committed Sep 27, 2022
1 parent 1c93491 commit 95291df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:/swc-project/swc/issues/3899)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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:/ArnaudBarre)",
"main": "src/swc-react-refresh.js",
Expand Down
8 changes: 7 additions & 1 deletion src/swc-react-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -57,6 +62,7 @@ export const swcReactRefresh = (): PluginOption => ({
});

if (
!automaticRuntime &&
result.code.includes("React.createElement") &&
!importReactRE.test(result.code)
) {
Expand Down

0 comments on commit 95291df

Please sign in to comment.