# @amoutonbrady/vite-plugin-solid

> solid-js integration plugin for vite

Latest version **0.4.2** (published 2020-11-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install @amoutonbrady/vite-plugin-solid
pnpm add @amoutonbrady/vite-plugin-solid
yarn add @amoutonbrady/vite-plugin-solid
bun add @amoutonbrady/vite-plugin-solid
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2020-11-23 |
| First published | 2020-07-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 (+17 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 522 |
| Author | Alexandre Mouton-Brady <amoutonbrady@gmail.com> |
| Maintainers | amoutonbrady |
| Keywords | vite, vite plugin, vitejs, vitejs plugin, solid |

## Links

- npm: https://www.npmjs.com/package/@amoutonbrady/vite-plugin-solid
- Repository: https://github.com/amoutonbrady/vite-plugin-solid
- Homepage: https://github.com/amoutonbrady/vite-plugin-solid#readme
- Issues: https://github.com/amoutonbrady/vite-plugin-solid/issues
- npm.io page: https://npm.io/package/@amoutonbrady/vite-plugin-solid

## Dependencies (7)

- [vite](https://npm.io/package/vite.md) ^1.0.0-rc.9
- [dedent](https://npm.io/package/dedent.md) ^0.7.0
- [solid-js](https://npm.io/package/solid-js.md) ^0.22.5
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.12.7
- [babel-preset-solid](https://npm.io/package/babel-preset-solid.md) ^0.22.5
- [@rollup/plugin-babel](https://npm.io/package/@rollup/plugin-babel.md) ^5.2.1
- [@babel/preset-typescript](https://npm.io/package/@babel/preset-typescript.md) ^7.12.7

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2020-11-23
- 0.4.1 — 2020-11-23
- 0.4.0 — 2020-11-23
- 0.3.0 — 2020-11-06
- 0.2.0 — 2020-09-25
- 0.1.1 — 2020-08-13
- 0.1.0 — 2020-07-31
- 0.0.4 — 2020-07-21
- 0.0.3 — 2020-07-12
- 0.0.2 — 2020-07-12
- 0.0.1 — 2020-07-12

## README

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

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
$ 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

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

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
// This variable is mandatory if you want automatic HMR
export const dispose = render(() => App, rootElement);

// The plugin will automatically inject the following snippet :

// 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);
}
```

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

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

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

---
_Source: https://npm.io/package/@amoutonbrady/vite-plugin-solid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
