Skip to content

Commit 3a2a341

Browse files
committed
refactor: merge plugin-react-swc in
2 parents 19e0231 + bc413b9 commit 3a2a341

File tree

138 files changed

+7293
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+7293
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
extends: ["config:base", "schedule:weekly", "group:allNonMajor"],
3+
labels: ["dependencies"],
4+
rangeStrategy: "bump",
5+
packageRules: [
6+
{ depTypeList: ["peerDependencies"], enabled: false },
7+
{
8+
"matchFileNames": ["**/react-18/**"],
9+
"ignoreDeps": ["react", "react-dom", "@types/react", "@types/react-dom"]
10+
},
11+
{
12+
"matchDepTypes": ["action"],
13+
"excludePackagePrefixes": ["actions/", "github/"],
14+
"pinDigests": true,
15+
},
16+
],
17+
ignoreDeps: [
18+
"generouted", // testing lib shipping JSX (new version ship transpiled JS)
19+
"prettier", // waiting for stable choice on ternaries
20+
],
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
permissions: {}
10+
jobs:
11+
ci:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: pnpm/action-setup@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 22
19+
cache: "pnpm"
20+
- run: pnpm install --frozen-lockfile --prefer-offline
21+
- uses: actions/cache@v4
22+
with:
23+
key: playwright-bin
24+
path: ~/.cache/ms-playwright
25+
- run: pnpm playwright install chromium
26+
- run: pnpm qa
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
id-token: write
10+
contents: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
environment: Release
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: pnpm/action-setup@v4
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
registry-url: "https://registry.npmjs.org"
23+
cache: "pnpm"
24+
- run: pnpm install --frozen-lockfile --prefer-offline
25+
- run: pnpm build
26+
- run: pnpm tnode scripts/publish.ts ${{ github.ref_name }}
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
29+
- uses: ArnaudBarre/github-release@v1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
node_modules/
3+
dist/
4+
playground-temp/
5+
test-results/
6+
.swc/
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
## 3.8.1
6+
7+
### Remove WebContainers warning [#268](https://github.com/vitejs/vite-plugin-react-swc/pull/268)
8+
9+
SWC is now supported in WebContainers 🎉
10+
11+
## 3.8.0
12+
13+
### Add useAtYourOwnRisk_mutateSwcOptions option
14+
15+
The future of Vite is with OXC, and from the beginning this was a design choice to not exposed too many specialties from SWC so that Vite React users can move to another transformer later.
16+
Also debugging why some specific version of decorators with some other unstable/legacy feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`.
17+
18+
```ts
19+
react({
20+
useAtYourOwnRisk_mutateSwcOptions(options) {
21+
options.jsc.parser.decorators = true;
22+
options.jsc.transform.decoratorVersion = "2022-03";
23+
},
24+
});
25+
```
26+
27+
## 3.7.2
28+
29+
### Add Vite 6 to peerDependencies range [#207](https://github.com/vitejs/vite-plugin-react-swc/pull/207)
30+
31+
Thanks @RobinTail
32+
33+
### Revert throw when refresh runtime is loaded twice [#237](https://github.com/vitejs/vite-plugin-react-swc/issues/237)
34+
35+
Revert the throw when refresh runtime is loaded twice to enable usage in micro frontend apps. This was added to help fix setup usage, and this is not worth an annoying warning for others or a config parameter.
36+
37+
This revert was done in the Babel plugin last year and I didn't port it back.
38+
39+
## 3.7.1
40+
41+
Ignore directive sourcemap error [#231](https://github.com/vitejs/vite-plugin-react-swc/issues/231)
42+
43+
## 3.7.0
44+
45+
### Support HMR for class components
46+
47+
This is a long overdue and should fix some issues people had with HMR when migrating from CRA.
48+
49+
## 3.6.0
50+
51+
### Add parserConfig option
52+
53+
This will unlock to use the plugin in some use cases where the original source code is not in TS. Using this option to keep using JSX inside `.js` files is highly discouraged and can be removed in any future version.
54+
55+
## 3.5.0
56+
57+
### Update peer dependency range to target Vite 5
58+
59+
There were no breaking change that impacted this plugin, so any combination of React plugins and Vite core version will work.
60+
61+
### Align jsx runtime for optimized dependencies
62+
63+
This will only affect people using internal libraries that contains untranspiled JSX. This change aligns the optimizer with the source code and avoid issues when the published source don't have `React` in the scope.
64+
65+
Reminder: While being partially supported in Vite, publishing TS & JSX outside of internal libraries is highly discouraged.
66+
67+
## 3.4.1
68+
69+
### Add support for `.mts` (fixes [#161](https://github.com/vitejs/vite-plugin-react-swc/issues/161))
70+
71+
Using CJS in source code will not work in Vite (and will never be supported), so this is better to only use `.ts`.
72+
73+
But to better align with [Vite core defaults](https://vitejs.dev/config/shared-options.html#resolve-extensions), `.mts` extension will now be processed like `.ts`. This maybe reverted in a future major.
74+
75+
## 3.4.0
76+
77+
- Add `devTarget` option (fixes [#141](https://github.com/vitejs/vite-plugin-react-swc/issues/141))
78+
- Disable Fast Refresh based on `config.server.hmr === false` instead of `process.env.TEST`
79+
- Warn when plugin is in WebContainers (see [#118](https://github.com/vitejs/vite-plugin-react-swc/issues/118))
80+
- Better invalidation message when an export is added & fix HMR for export of nullish values ([#143](https://github.com/vitejs/vite-plugin-react-swc/issues/143))
81+
82+
## 3.3.2
83+
84+
- Support [Vitest deps.experimentalOptimizer](https://vitest.dev/config/#deps-experimentaloptimizer) ([#115](https://github.com/vitejs/vite-plugin-react-swc/pull/115))
85+
86+
## 3.3.1
87+
88+
- Add `type: module` to package.json ([#101](https://github.com/vitejs/vite-plugin-react-swc/pull/101)). Because the library already publish `.cjs` & `.mjs` files, the only change is for typing when using the node16 module resolution (fixes [#95](https://github.com/vitejs/vite-plugin-react-swc/issues/95))
89+
- Throw an error when the MDX plugin is after this one ([#100](https://github.com/vitejs/vite-plugin-react-swc/pull/100)). This is an expected breaking change added in `3.2.0` and this should people that were using both plugins before this version to migrate.
90+
91+
## 3.3.0
92+
93+
- Support TS/JSX in node_modules to help the community experiment with it. Note that for now this not supported by TS and errors from these files cannot be silenced if the user is using a stricter configuration than the library author: https://github.com/microsoft/TypeScript/issues/30511. I advise to use it only for internal libraries for now (fixes #53)
94+
- Silence `"use client"` warning when building library like `@tanstack/react-query`
95+
- Fix fast refresh issue when exporting a component with a name that shadow another local component
96+
97+
This release goes in hand with the upcoming Vite 4.3 release focusing on performances:
98+
99+
- Move resolve of runtime code into a "pre" plugin ([#79](https://github.com/vitejs/vite-plugin-react-swc/pull/79))
100+
- Wrap dynamic import to speedup analysis ([#80](https://github.com/vitejs/vite-plugin-react-swc/pull/80))
101+
102+
## 3.2.0
103+
104+
- Support HMR for MDX (fixes #52)
105+
- Fix: when using plugins, apply SWC before esbuild so that automatic runtime is respected for JSX (fixes #56)
106+
- Fix: use jsxImportSource in optimizeDeps
107+
108+
## 3.1.0
109+
110+
- Support plugins via the new `plugins` options
111+
- Support TypeScript decorators via the new `tsDecorators` option. This requires `experimentalDecorators` in tsconfig.
112+
- Fix HMR for styled components exported alongside other components
113+
- Update embedded refresh runtime to 0.14 (fixes [#46](https://github.com/vitejs/vite-plugin-react-swc/issues/46))
114+
115+
## 3.0.1
116+
117+
- Support Emotion via the new `jsxImportSource` option (fixes [#25](https://github.com/vitejs/vite-plugin-react-swc/issues/25))
118+
119+
To use it with Emotion, update your config to:
120+
121+
```ts
122+
export default defineConfig({
123+
plugins: [react({ jsxImportSource: "@emotion/react" })],
124+
});
125+
```
126+
127+
- Fix HMR when using Vite `base` option (fixes [#18](https://github.com/vitejs/vite-plugin-react-swc/issues/18))
128+
- Fix usage with workers (fixes [#23](https://github.com/vitejs/vite-plugin-react-swc/issues/23))
129+
- Fix usage with `Vite Ruby` and `Laravel Vite` ([#20](https://github.com/vitejs/vite-plugin-react-swc/pull/20))
130+
- Fix plugin default export when using commonjs (fixes [#14](https://github.com/vitejs/vite-plugin-react-swc/issues/14))
131+
132+
## 3.0.0
133+
134+
This is plugin is now stable! 🎉
135+
136+
To migrate from `vite-plugin-swc-react-refresh`, see the `3.0.0-beta.0` changelog.
137+
138+
## 3.0.0-beta.2
139+
140+
- breaking: update plugin name to `vite:react-swc` to match official plugins naming
141+
- fix: don't add React Refresh wrapper for SSR transform (fixes [#11](https://github.com/vitejs/vite-plugin-react-swc/issues/11))
142+
143+
## 3.0.0-beta.1
144+
145+
Fix package.json exports fields
146+
147+
## 3.0.0-beta.0
148+
149+
This is the first beta version of the official plugin for using [SWC](https://swc.rs/) with React in Vite!
150+
151+
Some breaking changes have been made to make the plugin closer to the Babel one while keeping the smallest API surface possible to reduce bugs, encourage future-proof compilation output and allow easier opt-in into future perf improvements (caching, move to other native toolchain, ...):
152+
153+
- Automatically enable automatic JSX runtime. "classic" runtime is not supported
154+
- Skip transformation for `.js` files
155+
- Enforce [useDefineForClassFields](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier)
156+
- Don't pass `esbuild.define` config option to SWC. You can use the [top level define option](https://vitejs.dev/config/shared-options.html#define) instead
157+
- Use default export
158+
159+
To migrate, change your config to:
160+
161+
```js
162+
import { defineConfig } from "vite";
163+
import react from "@vitejs/plugin-react-swc";
164+
165+
export default defineConfig({
166+
plugins: [react()],
167+
});
168+
```
169+
170+
This new release also include a runtime check for React refresh boundaries. When the conditions are not met (most of the time, exporting React components alongside functions or constant), the module is invalidated with a warning message to help you catch issues while keeping you page up-to date with code changes.
171+
172+
## 2.2.1
173+
174+
Skip react-refresh on SSR (Fixes [#2](https://github.com/vitejs/vite-plugin-react-swc/issues/2))
175+
176+
## 2.2.0
177+
178+
- Always provide parser options to fix issue with `.jsx` imports. Relying on file extension for this is more buggy [than I though](https://github.com/swc-project/swc/issues/3297)
179+
- Extract line and column in SWC errors to make overlay filename clickable
180+
- Fix plugin name (`react-refresh` -> `swc-react-refresh`)
181+
182+
## 2.1.0
183+
184+
Add source maps support
185+
186+
## 2.0.3
187+
188+
Include `react/jsx-dev-runtime` for dependencies optimisation when using automatic runtime.
189+
190+
## 2.0.2
191+
192+
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)
193+
194+
## 2.0.1
195+
196+
Fix esbuild property in documentation.
197+
198+
## 2.0.0
199+
200+
Breaking: Use named export instead of default export for better esm/cjs interop.
201+
202+
To migrate, replace your import by `import { swcReactRefresh } from "vite-plugin-swc-react-refresh";`
203+
204+
The JSX automatic runtime is also now supported if you bump esbuild to at least [0.14.51](https://github.com/evanw/esbuild/releases/tag/v0.14.51).
205+
206+
To use it, update your config from `esbuild: { jsxInject: 'import React from "react"' },` to `esbuild: { jsx: "automatic" },`
207+
208+
## 0.1.2
209+
210+
- Add vite as peer dependency
211+
- Pin @swc/core version to 1.2.141 to avoid a 30mb bump of bundle size
212+
213+
## 0.1.1
214+
215+
Add LICENSE
216+
217+
## 0.1.0
218+
219+
Initial release

packages/plugin-react-swc/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Arnaud Barré (https://github.com/ArnaudBarre)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)