-
Notifications
You must be signed in to change notification settings - Fork 51
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 004bebf
Showing
12 changed files
with
4,866 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,3 @@ | ||
node_modules | ||
lib | ||
dist |
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,156 @@ | ||
# ⚡ Vite Plugin Solid | ||
|
||
A simple integration to run [solid-js](https://github.com/ryansolid/solid) with [vite](https://github.com/vitejs/vite) | ||
|
||
## Features | ||
|
||
- HMR with minimal configuration | ||
- Drop-in installation as vite plugin | ||
- Minimal bundle size (5.82kb non gzip for a [Hello World](./playground/src/main.tsx)) | ||
- Support typescript (`.js .ts .jsx .tsx`) out of the box | ||
- Support code splitting out of the box | ||
|
||
# Quickstart | ||
|
||
```bash | ||
npx degit amoutonbrady/vite-plugin-solid/playground my-solid-project | ||
cd my-solid-project | ||
npm install | ||
npm run dev # starts dev-server with hot-module-reloading | ||
npm run build # builds to /dist | ||
``` | ||
|
||
# Usage | ||
|
||
## Installation | ||
|
||
Install vite and vite-plugin-solid as dev dependencies | ||
|
||
```bash | ||
$ npm install -D vite @amoutonbrady/vite-plugin-solid # with npm | ||
$ pnpm add -D vite @amoutonbrady/vite-plugin-solid # with pnpm | ||
$ yarn add -D vite @amoutonbrady/vite-plugin-solid # with yarn | ||
``` | ||
|
||
Add it as plugin to `vite.config.ts` | ||
|
||
```ts | ||
// vite.config.ts | ||
import { UserConfig } from "vite"; | ||
import { solidPlugin } from '@amoutonbrady/vite-plugin-solid'; | ||
|
||
const config: UserConfig = { | ||
root: "src", | ||
outDir: "dist", | ||
plugins: [solidPlugin()], | ||
// Vite and Esbuild being opinionated about how to manage JSX, | ||
// you need to disable it to prevent extra stuff going in your bundle | ||
// Luckily, vite is still quite fast even skipping Esbuild | ||
enableEsbuild: false, | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
Or `vite.config.js` | ||
|
||
```js | ||
// vite.config.js | ||
import { solidPlugin } from '@amoutonbrady/vite-plugin-solid'; | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
const config = { | ||
root: "src", | ||
outDir: "dist", | ||
plugins: [solidPlugin()], | ||
// Vite and Esbuild being opinionated about how to manage JSX, | ||
// you need to disable it to prevent extra stuff going in your bundle | ||
// Luckily, vite is still quite fast even skipping Esbuild | ||
enableEsbuild: false, | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
Finally you have to add a bit of code to your entry point to activate HMR. This might be handled automatically at some point by the plugin but for now it's manual. | ||
|
||
```ts | ||
const rootEl = document.getElementById("app"); | ||
const dispose = render(() => App, rootEl); | ||
|
||
// HMR stuff, this will be automatically removed during build | ||
// /!\ You need to add "vite" in the "compilerOptions.types" of your tsconfig.json | ||
// if you want to avoid type errors here | ||
if (import.meta.hot) { | ||
import.meta.hot.accept(); | ||
import.meta.hot.dispose(() => { | ||
dispose(); | ||
rootEl.textContent = ""; | ||
}); | ||
} | ||
``` | ||
|
||
## Run | ||
|
||
Just use regular `vite` or `vite build` commands | ||
|
||
```json | ||
{ | ||
..., | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build" | ||
} | ||
..., | ||
} | ||
``` | ||
|
||
## Plugin options | ||
|
||
You can pass options to the plugin via `vite.config.(js|ts)` | ||
|
||
```js | ||
import { solidPlugin } from '@amoutonbrady/vite-plugin-solid'; | ||
|
||
const options = { | ||
babel: { | ||
presets: ['@babel/preset-env'], | ||
}, | ||
}; | ||
|
||
const config = { | ||
root: "src", | ||
outDir: "dist", | ||
plugins: [solidPlugin(options)], | ||
enableEsbuild: false, | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
For now the only options is to add extra babel config. | ||
|
||
## Example | ||
|
||
You can checkout the [playground](/playground) | ||
|
||
More example will come to full proof the plugin | ||
|
||
# Limitations | ||
|
||
This is an early version, some things may not work as expected. Please report findings. | ||
|
||
- HMR is manual and doesn't hold state on reload | ||
- ESBuild has to be deactivated because of its JSX management which slow downs a bit the reload | ||
- Vite is primarly build for Vue and therefore includes it when installing it | ||
|
||
# Got a question? / Need help? | ||
|
||
Join [solid discord](https://discord.com/invite/solidjs) | ||
|
||
# Credits | ||
|
||
- [solid-js](https://github.com/ryansolid/solid) and [vite](https://github.com/vitejs/vite#readme) obviously | ||
- [svite](https://github.com/rixo) - initial inspiration (also based this readme on it) |
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,46 @@ | ||
{ | ||
"name": "@amoutonbrady/vite-plugin-solid", | ||
"version": "0.0.1", | ||
"description": "solid-js integration plugin for vite", | ||
"main": "lib/plugin.js", | ||
"files": [ | ||
"lib/*" | ||
], | ||
"types": "lib", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/amoutonbrady/vite-plugin-solid.git" | ||
}, | ||
"keywords": [ | ||
"vite", | ||
"vite plugin", | ||
"vitejs", | ||
"vitejs plugin", | ||
"solid" | ||
], | ||
"author": "Alexandre Mouton-Brady <[email protected]>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/amoutonbrady/vite-plugin-solid/issues" | ||
}, | ||
"homepage": "https://github.com/amoutonbrady/vite-plugin-solid#readme", | ||
"peerDependencies": { | ||
"solid-js": "^0.18.12 || ^1.0.0", | ||
"vite": "^1.0.0-beta.11 || ^1.0.0" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.10.4", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@rollup/plugin-babel": "^5.0.4", | ||
"babel-preset-solid": "^0.18.12", | ||
"solid-js": "^0.18.12", | ||
"vite": "^1.0.0-beta.11" | ||
}, | ||
"devDependencies": { | ||
"@types/babel__core": "^7.1.9", | ||
"typescript": "^4.0.0-dev.20200712" | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"name": "solid-vite-playground", | ||
"version": "0.0.0", | ||
"description": "My solid application", | ||
"author": "Alexandre Mouton-Brady <[email protected]>", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build" | ||
}, | ||
"devDependencies": { | ||
"solid-js": "^0.18.12", | ||
"vite": "^1.0.0-beta.11" | ||
}, | ||
"license": "ISC" | ||
} |
Oops, something went wrong.