Skip to content

Commit

Permalink
✨ Improved and document the code based on the vue jsx plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutonbrady committed Jan 4, 2021
1 parent 864d016 commit 4efa4d9
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 135 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For other breaking changes, check [the migration guide of vite](https://vitejs.d
- HMR with minimal configuration
- Drop-in installation as vite plugin
- 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 typescript (`.jsx .tsx`) out of the box, even when exported as `source` in the `node_modules`
- Support code splitting out of the box

## Quickstart
Expand All @@ -32,15 +32,23 @@ $ npm run build # builds to /dist

## Installation

Install `vite` and `vite-plugin-solid` as dev dependencies
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.

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

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

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

Add it as plugin to `vite.config.ts`
Expand All @@ -61,7 +69,7 @@ Or `vite.config.js`

```js
// vite.config.js
import { solidPlugin } from "vite-plugin-solid";
import solidPlugin from "vite-plugin-solid";

/**
* @type {import('vite').UserConfig}
Expand All @@ -75,6 +83,8 @@ 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.

*NB: This is actually a partial HMR, it doesn't retain any state, it just reload the page without reloading the page...*

```ts
const dispose = render(() => App, rootElement);

Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-solid",
"version": "0.5.0",
"version": "0.6.0",
"description": "solid-js integration plugin for vite 2",
"files": [
"dist"
Expand All @@ -16,6 +16,7 @@
"types": "dist/types/index.d.ts",
"scripts": {
"build": "rollup -c && tsc --emitDeclarationOnly",
"dev": "rollup -c -w",
"prepublishOnly": "pnpm build",
"check": "package-check"
},
Expand All @@ -37,15 +38,19 @@
},
"homepage": "https://github.com/amoutonbrady/vite-plugin-solid#readme",
"peerDependencies": {
"vite": "^2"
"solid-js": "^0.23",
"vite": "^2.0.0-beta.4",
"babel-preset-solid": "^0.23"
},
"dependencies": {
"@babel/core": "^7.12.7",
"@babel/preset-typescript": "^7.12.7",
"babel-preset-solid": "^0.23.5",
"vite": "^2.0.0-beta.1"
"babel-preset-solid": "^0.23",
"solid-js": "^0.23",
"vite": "^2.0.0-beta.4"
},
"devDependencies": {
"@babel/plugin-transform-typescript": "^7.12.1",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-node-resolve": "^11.0.1",
"@skypack/package-check": "^0.2.2",
Expand Down
20 changes: 10 additions & 10 deletions playground/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Playground</title>
</head>
<body>
<div id="app"></div>
<script src="./index.tsx" type="module"></script>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Playground</title>
</head>
<body>
<div id="app"></div>
<script src="./index.jsx" type="module"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions playground/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render } from 'solid-js/web';
import { Router, Route } from 'solid-app-router';

const App = () => <Route />;

const routes = [
{
path: '/',
component: () => <h1>Hello world</h1>,
},
];

const dispose = render(
() => (
<Router routes={routes}>
<App />
</Router>
),
document.getElementById('app'),
);

if (import.meta.hot) {
import.meta.hot.accept();
import.meta.hot.dispose(dispose);
}
8 changes: 0 additions & 8 deletions playground/index.tsx

This file was deleted.

6 changes: 4 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"author": "Alexandre Mouton-Brady",
"license": "ISC",
"devDependencies": {
"vite": "^2.0.0-beta.1"
"vite": "^2.0.0-beta.4"
},
"dependencies": {
"solid-js": "^0.23.6"
"@vitejs/plugin-vue": "^1.0.3",
"solid-app-router": "^0.0.19",
"solid-js": "^0.23.8"
}
}
36 changes: 28 additions & 8 deletions playground/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { solidPlugin } from '..';
import solid from '..';
import type { UserConfig } from 'vite';

const config: UserConfig = {
plugins: [solidPlugin()],
plugins: [solid()],
};

export default config;

0 comments on commit 4efa4d9

Please sign in to comment.