Skip to content

Commit

Permalink
refactor: make this a proper vite plugin, closes #7, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Oct 1, 2022
1 parent 6d89b8e commit a54f29f
Show file tree
Hide file tree
Showing 46 changed files with 4,756 additions and 216 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/test.yml
Expand Up @@ -21,14 +21,19 @@ jobs:
cache: pnpm
- run: pnpm install
- run: pnpm build
- run: pnpm type:check
- run: pnpm ts:check
- run: pnpm format:check
- name: e2e init info
- name: install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf
- name: build example
run: |
pnpm create vite example --template vue
cd example
pnpm i
pnpm add .. -D
pnpm add @tauri-apps/cli -D
pnpm vite-tauri init
pnpm vite-tauri info
pnpm build:tauri
6 changes: 2 additions & 4 deletions .gitignore
Expand Up @@ -6,12 +6,10 @@ yarn-error.log*

node_modules/

example/

.vscode/
.idea/

*.tgz

bin/
tauri-cli-v*
/dist
/example/dist
76 changes: 55 additions & 21 deletions README.md
Expand Up @@ -17,37 +17,71 @@ yarn add -D vite-plugin-tauri @tauri-apps/cli
npm i -D vite-plugin-tauri @tauri-apps/cli
```

And only if you're using npm, add the following:
## Usage

```ts
// vite.config.js
import { defineConfig } from 'vite'
import { tauri } from "vite-plugin-tauri" // 1. import the plugin
export default defineConfig({
plugins: [
tauri(), // 2. add it to the plugins list
]
})
```

## Options

### `debug`

- **Type:** `bool`
- **Default:** `false`

Enable or disable building Tauri in debug mode.

## Advanced Usage

### Use a separate config for Tauri

Create a `vite.config.tauri.js` with the following content

```ts
import { defineConfig, mergeConfig } from "vite";
import baseViteConfig from "./vite.config";
import { tauri } from "vite-plugin-tauri";

export default defineConfig(
mergeConfig(
baseViteConfig,
defineConfig({
plugins: [
tauri()
],
})
)
);
```

Modify `package.json`:

```diff
// package.json
{
..
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
+ "vite-tauri": "vite-tauri",
}
+ "dev:tauri": "vite --config vite.config.tauri.js",
+ "build:tauri": "vite build --config vite.config.tauri.js",
"preview": "vite preview"
},
..
}
```

## Usage

```sh
# pnpm
pnpm vite-tauri <subcommand>
# yarn
yarn vite-tauri <subcommand>
# npm
npm run vite-tauri <subcommand>
```

#### Supported Subcommands:

- `dev` - Starts your Vite/Tauri app with hot reload.
- `build` - Builds your Vite/Tauri executable and installer.
- All other Tauri CLI [subcommands and flags](https://tauri.studio/docs/api/cli) are supported.
Now you can build or develop Tauri without chaning your existing web dev flow.

## License

[MIT](./LICENSE) License
[MIT](./LICENSE) © Amr Bashir
3 changes: 3 additions & 0 deletions example/README.md
@@ -0,0 +1,3 @@
# Vite + Tauri Example

This example demonstrates the [advanced usage](../README.md#advanced-usage) of the plugin and is used for testing the plugin in CI.
13 changes: 13 additions & 0 deletions example/index.html
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions example/package.json
@@ -0,0 +1,22 @@
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"dev:tauri": "vite --config vite.config.tauri.js",
"build:tauri": "vite build --config vite.config.tauri.js",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.37"
},
"devDependencies": {
"vite-plugin-tauri": "link:..",
"@tauri-apps/cli": "^1.1.1",
"@vitejs/plugin-vue": "^3.1.0",
"vite": "^3.1.0"
}
}

0 comments on commit a54f29f

Please sign in to comment.