New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-solid

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-solid

solid-js integration plugin for vite 2

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
75K
decreased by-5.26%
Maintainers
1
Weekly downloads
 
Created
Source

⚡ vite-plugin-solid

A simple integration to run solid-js with vite

HMR gif demonstrationdemodemodemo

Got a question? / Need help?

Join solid discord and check the troubleshooting section to see if your question hasn't been already answered.

Features

  • HMR with no configuration needed
  • Drop-in installation as a vite plugin
  • Minimal bundle size
  • Support typescript (.tsx) out of the box
  • Support code splitting out of the box

Quickstart

You can use the vite-template-solid starter templates similar to CRA:

$ npx degit amoutonbrady/vite-template-solid/js my-project
$ cd my-project
$ npm install # or pnpm install or yarn install
$ npm run start # starts dev-server with hot-module-reloading
$ npm run build # builds to /dist

Installation

Install vite, vite-plugin-solid and babel-preset-solid as dev dependencies.

Install solid-js as dependency.

You have to install those so that you are in control to which solid version is used to compile your code.

# with npm
$ npm install -D vite vite-plugin-solid babel-preset-solid
$ npm install solid-js

# with pnpm
$ pnpm add -D vite vite-plugin-solid babel-preset-solid
$ pnpm add solid-js

# with yarn
$ yarn add -D vite vite-plugin-solid babel-preset-solid
$ yarn add solid-js

Add it as plugin to vite.config.js

// vite.config.ts
import { defineConfig } from 'vite';
import { solidPlugin } from 'vite-plugin-solid';

export default defineConfig({
  plugins: [solidPlugin()],
});

Run

Just use regular vite or vite build commands

{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}

API

options

  • Type: Object
  • Default: {}
options.dev
  • Type: Boolean
  • Default: true

This will inject solid-js/dev in place of solid-js in dev mode. Has no effect in prod. If set to false, it won't inject it in dev. This is useful for extra logs and debug.

options.hmr
  • Type: Boolean
  • Default: true

This will inject HMR runtime in dev mode. Has no effect in prod. If set to false, it won't inject the runtime in dev.

options.ssr
  • Type: Boolean
  • Default: false

This will force SSR code in the produced files. This is experiemental and mostly not working yet.

Note on HMR

Starting from version 1.1.0, this plugin handle automatic HMR via solid-refresh.

At this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:

  • Every component that you expect to have HMR should be exported as default eg:
const MyComponent = () => <h1>My component</h1>;
export default MyComponent;
  • When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.

  • The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.

  • Currently there's a parsing issue if you export default on the same line as declaration like so: export default function App() {...}. It should be made in two steps. First declare then export, similar to the example in the first bullet point.

If at least one of this point is blocking to you, you can revert to the old behavior but opting out the automatic HMR and placing the following snippet in your entry point:

const dispose = render(() => <App />, document.body);

if (import.meta.hot) {
  import.meta.accept();
  import.meta.dispose(dispose);
}

Troubleshooting

  • It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow this thread and disable the "Safe Write" option in "Settings | Appearance & Behavior | System Settings".

  • If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the dependecies optimization

Migration from v1

The master branch now target vite 2.

The main breaking change from previous version is that the package has been renamed from @amoutonbrady/vite-plugin-solid to vite-plugin-solid.

For other breaking changes, check the migration guide of vite.

Credits

Keywords

FAQs

Package last updated on 19 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc