Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for vite #1857

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions docs-website/docs/docs/Installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ backtrace:

## Web setup

This guide assumes you use Webpack as your bundler.

1. If you haven't already, install Babel plugins for decorators, static class properties, and async/await to get the most out of Watermelon. This assumes you use Babel 7 and already support ES6 syntax.
If you haven't already, install Babel plugins for decorators, static class properties, and async/await to get the most out of Watermelon. This assumes you use Babel 7 and already support ES6 syntax.

```bash
yarn add --dev @babel/plugin-proposal-decorators
Expand All @@ -315,7 +313,8 @@ This guide assumes you use Webpack as your bundler.
npm install -D @babel/plugin-transform-runtime
```

2. Add ES7 support to your `.babelrc` file:
### Webpack
If you're using Webpack, add ES7 support to your `.babelrc` file:
```json
{
"plugins": [
Expand All @@ -332,6 +331,62 @@ This guide assumes you use Webpack as your bundler.
}
```

### Vite
If you're using Vite, you'll need to edit your vite.config.js file.

If you're working with React, ensure your config looks something like this:
```js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [
react({
babel: {
plugins: [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
[
"@babel/plugin-transform-runtime",
{
"helpers": true,
"regenerator": true
}
]
],
}
}),
]
});
```
If you're not using React, you can try this (untested):
```js
import { defineConfig } from 'vite';
import babel from 'vite-plugin-babel';

export default defineConfig({
plugins: [
babel({
babelConfig: {
babelrc: false,
configFile: false,
plugins: [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
[
"@babel/plugin-transform-runtime",
{
"helpers": true,
"regenerator": true
}
]
],
},
}),
]
});
```

## Windows (React Native)

WatermelonDB has **experimental** support for [React Native Windows](https://microsoft.github.io/react-native-windows/), added in v0.27.
Expand Down
Loading