-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ced984
Showing
9 changed files
with
1,053 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Publish to npm | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
if: ${{ contains(github.event.head_commit.message, '[publish]') }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn install --frozen-lockfile | ||
- run: yarn prettier-ci | ||
- run: yarn build | ||
# Setup .npmrc file to publish to npm | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: "16.x" | ||
registry-url: "https://registry.npmjs.org" | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
node_modules/ | ||
*.js | ||
*.d.ts | ||
!src/refresh-runtime.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.ts | ||
!*.d.ts | ||
tsconfig.json | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# vite-plugin-swc-react-refresh [![npm](https://img.shields.io/npm/v/vite-plugin-swc-react-refresh)](https://www.npmjs.com/package/vite-plugin-swc-react-refresh) | ||
|
||
Use the versatility of [swc](https://swc.rs/) for development and the maturity of [esbuild](https://esbuild.github.io/) for production. | ||
|
||
- ✅ A fast Fast Refresh (~20x faster than Babel) | ||
- ✅ Skip `import React` | ||
- ❌ Not compatible with [automatic JSX runtime](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html). See [this section](#jsx-runtime) | ||
- ❌ Don't check for consistent components exports. See [this section](#consistent-components-exports) | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i -D vite-plugin-swc-react-refresh | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { defineConfig } from "vite"; | ||
import swcReactRefresh from "vite-plugin-swc-react-refresh"; | ||
|
||
export default defineConfig({ | ||
plugins: [swcReactRefresh()], | ||
esbuild: { jsxInject: `import React from "react"` }, | ||
}); | ||
``` | ||
|
||
## JSX Runtime | ||
|
||
This plugin is only used in development, and esbuild (which doesn't support the automatic JSX runtime) will be used by Vite for bundling. However, you can omit the default React import with the `esbuild.jsxInject` Vite option. | ||
|
||
## Consistent components exports | ||
|
||
For React refresh to work, your file should only export React components. The best explanation I've read is the one from the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works). | ||
|
||
However, having some components being hot updated and not others is a very frustrating experience as a developer, and I think this rule should be enforced by a linter, so I made an [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) to go along with this plugin. | ||
|
||
This plugin expects this rule to be respected and will always fast refresh components. If a file export something that is not a React component (TS types are ok), update to this export would not propagate and require a manual reload. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "vite-plugin-swc-react-refresh", | ||
"description": "Use the versatility of swc for development and the maturity of esbuild for production", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"author": "Arnaud Barré (https://github.com/ArnaudBarre)", | ||
"main": "src/swc-react-refresh.js", | ||
"repository": "github:ArnaudBarre/vite-plugin-swc-react-refresh", | ||
"keywords": [ | ||
"vite", | ||
"vite-plugin", | ||
"react", | ||
"swc", | ||
"react-refresh", | ||
"fast refresh" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"prettier": "yarn prettier-ci --write", | ||
"prettier-ci": "prettier --check '**/*.{js,ts,json,md,yml}'" | ||
}, | ||
"prettier": { | ||
"trailingComma": "all" | ||
}, | ||
"dependencies": { | ||
"@swc/core": "^1.2.133" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.5.4", | ||
"vite": "^2.7.13" | ||
} | ||
} |
Oops, something went wrong.