Skip to content

Commit

Permalink
📝 Updating readme for vite 2
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutonbrady committed Jan 2, 2021
1 parent 75126cf commit 298205f
Showing 1 changed file with 13 additions and 63 deletions.
76 changes: 13 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,50 @@

A simple integration to run [solid-js](https://github.com/ryansolid/solid) with [vite](https://github.com/vitejs/vite)

This targets vite 2 (which is in beta right now). To checkout vite 1 support, check out the `vite-1.x` branch.

## 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))
- Minimal bundle size (5.99kb 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
## Quickstart

You can use the [vite-template-solid](https://github.com/amoutonbrady/vite-template-solid) starter templates similar to CRA:

```bash
$ npx degit amoutonbrady/vite-template-solid/js#main my-project
$ npx degit amoutonbrady/vite-template-solid/js my-project
$ cd my-project
$ npm install # or pnpm install or yarn 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
Install `vite` and `vite-plugin-solid` as dev dependencies

```bash
# with npm
$ npm install -D vite @amoutonbrady/vite-plugin-solid
$ npm install -D vite vite-plugin-solid solid-js
# with pnpm
$ pnpm add -D vite @amoutonbrady/vite-plugin-solid
$ pnpm add -D vite vite-plugin-solid solid-js
# with yarn
$ yarn add -D vite @amoutonbrady/vite-plugin-solid
$ yarn add -D vite vite-plugin-solid solid-js
```

Add it as plugin to `vite.config.ts`

```ts
// vite.config.ts
import { UserConfig } from "vite";
import { solidPlugin } from "@amoutonbrady/vite-plugin-solid";
import { solidPlugin } from "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;
Expand All @@ -61,19 +55,13 @@ Or `vite.config.js`

```js
// vite.config.js
import { solidPlugin } from "@amoutonbrady/vite-plugin-solid";
import { solidPlugin } from "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;
Expand All @@ -82,14 +70,9 @@ 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
// This variable is mandatory if you want automatic HMR
export const dispose = render(() => App, rootElement);

// The plugin will automatically inject the following snippet :
const dispose = render(() => App, rootElement);

// 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);
Expand All @@ -109,39 +92,6 @@ Just use regular `vite` or `vite build` commands
}
```

## 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.

# 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

# Troubleshooting

It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow [this thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000154544-I-m-having-a-huge-problem-with-Webstorm-and-react-hot-loader-) and disable the **"Safe Write"** option in **"Settings | Appearance & Behavior | System Settings"**.
Expand All @@ -153,4 +103,4 @@ 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)
- [vite](https://github.com/vitejs/vite) obviously

0 comments on commit 298205f

Please sign in to comment.