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

feat: Add Trunk, Next.js, Nuxt Frontend Guides #1405

Merged
merged 42 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
51b6d0e
feat: working on some mobile docs
simonhyll Aug 16, 2023
b5271a6
docs: committing current state
simonhyll Aug 21, 2023
be87d73
working on it
simonhyll Aug 21, 2023
20280ab
Merge branch 'next' into guide/mobile
lorenzolewis Sep 1, 2023
e523dc0
Move to create section
lorenzolewis Sep 1, 2023
14859f8
Switch to commandtabs component, update copy
lorenzolewis Sep 1, 2023
4255415
shift some files around
lorenzolewis Sep 1, 2023
1c994fa
move docs
lorenzolewis Sep 1, 2023
4335461
add to sidebar
lorenzolewis Sep 1, 2023
2fbe542
tweaks
lorenzolewis Sep 1, 2023
99b013f
revert
lorenzolewis Sep 1, 2023
9288698
format
lorenzolewis Sep 1, 2023
8059fa4
phrasing updates
lorenzolewis Sep 1, 2023
576b67d
Stub leptos guide
lorenzolewis Sep 1, 2023
717e66a
Stub qwik
lorenzolewis Sep 1, 2023
e5e1af1
stub Svelte
lorenzolewis Sep 1, 2023
33b8195
Stub sycamore
lorenzolewis Sep 1, 2023
d5ede7c
Stub vite
lorenzolewis Sep 1, 2023
bbc438b
stub webpack
lorenzolewis Sep 1, 2023
2f6374e
stub Yew
lorenzolewis Sep 1, 2023
8f792b4
fix typo
lorenzolewis Sep 1, 2023
f90e285
Update description
lorenzolewis Sep 1, 2023
059cb4b
update descriptions and comments
lorenzolewis Sep 1, 2023
9adb608
Add version to trunk guide
lorenzolewis Sep 1, 2023
8aab1d0
Revise wording
lorenzolewis Sep 1, 2023
204dc65
update to mention upstream issues, phrasing
lorenzolewis Sep 2, 2023
07042d1
Add telemetry as optional to checklist
lorenzolewis Sep 2, 2023
2e0c0c1
Remove optional build object in config
lorenzolewis Sep 2, 2023
064c28b
Apply suggestions from code review
lorenzolewis Sep 2, 2023
42807bb
remove setting that's already default
lorenzolewis Sep 2, 2023
32a0d95
rename Svelte file
lorenzolewis Sep 2, 2023
de87b43
Update src/content/docs/2/guide/frontend/trunk.mdx
lorenzolewis Sep 2, 2023
928532c
Cleanup Trunk
lorenzolewis Sep 2, 2023
c4de5d7
setup > configuration, remove install
lorenzolewis Sep 2, 2023
911d112
Add steps
lorenzolewis Sep 2, 2023
9a36c85
Add steps
lorenzolewis Sep 2, 2023
05fec03
Update src/content/docs/2/guide/frontend/nuxt.mdx
lorenzolewis Sep 2, 2023
74f1ca2
Add link to environment variables
lorenzolewis Sep 2, 2023
9966557
update to default port
lorenzolewis Sep 2, 2023
2d21361
Enable for i18n
lorenzolewis Sep 2, 2023
ec9bd40
add environment-variables stub
lorenzolewis Sep 2, 2023
8ce192a
Update src/content/docs/2/guide/frontend/trunk.mdx
lorenzolewis Sep 2, 2023
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
4 changes: 4 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default defineConfig({
label: 'Create a Project',
link: '/2/guide/create/',
},
{
label: 'Frontend Configuration',
link: '/2/guide/frontend/',
},
{
label: 'Upgrade & Migrate',
link: '2/guide/upgrade-migrate',
Expand Down
58 changes: 16 additions & 42 deletions src/content/docs/2/guide/create/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ Follow along with the prompts to choose your project name, frontend language, pa

:::tip[Not sure what to choose?]

We use [SolidJS](https://www.solidjs.com) throughout the Tauri documentation and examples. For the easiest way to follow along we recommend the following:
We recommend starting with the vanilla template (HTML, CSS, and JavaScript without a frontend framework) to get started. You can always [integrate a frontend framework](/2/guide/create/existing-project) later.

- Choose which language to use for your frontend: `TypeScript / JavaScript`
- Choose your package manager: `pnpm`
{/* TODO: Change phrasing in CTA from UI to frontend and Solid to SolidJS */}
- Choose your UI template: `Solid`
- Choose your UI template: `Vanilla`
- Choose your UI flavor: `TypeScript`

:::
Expand All @@ -76,58 +75,33 @@ We use [SolidJS](https://www.solidjs.com) throughout the Tauri documentation and

After `create-tauri-app` has complete you can navigate into your project's folder, install dependencies, then use the [Tauri CLI](/2/reference/cli) to start the development server:

<Tabs>
<TabItem label="npm">
import CommandTabs from '@components/CommandTabs.astro';

```sh
cd my-tauri-app
<CommandTabs
npm="cd my-tauri-app
npm install
npm run tauri dev
```

</TabItem>
<TabItem label="Yarn">

```sh
cd my-tauri-app
npm run tauri dev"
yarn="cd my-tauri-app
yarn install
yarn tauri dev
```

</TabItem>
<TabItem label="pnpm">

```sh
cd my-tauri-app
yarn tauri dev"
pnpm="cd my-tauri-app
pnpm install
pnpm tauri dev
```

</TabItem>
<TabItem label="Cargo">
pnpm tauri dev"
cargo="cd my-tauri-app
cargo tauri dev"
/>

```sh
cd my-tauri-app
cargo tauri dev
```

</TabItem>
</Tabs>

You'll now see a new window open with your app running:

TODO: Image of app here
You'll now see a new window open with your app running.

**Congratulations!** You've made your Tauri app! 🚀

<Card title="Next Steps" icon="rocket">
## Next Steps

- [Add and Configure a Frontend Framework](/2/guide/frontend)
- [Tauri Command Line Interface (CLI) Reference](/2/reference/cli)
- [Learn how to build your Tauri app](/2/guide/build)
- [Discover additional features and recipes to extend Tauri](/2/guide/list)

</Card>

<Card title="Additional Resources" icon="document">

List to best practices, blog posts, etc.
Expand Down
50 changes: 50 additions & 0 deletions src/content/docs/2/guide/frontend/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Frontend Configuration
i18nReady: true
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';

Tauri is frontend agnostic and supports most frontend frameworks out of the box. However, sometimes a framework need a bit of extra configuration to integrate with Tauri. Below is a list of frameworks with recommended configurations.

If a framework is not listed then it may work with Tauri with no additional configuration needed or it could have not been documented yet. Any contributions to add a framework that may require additional configuration are welcome to help others in the Tauri community.

:::tip[Framework Not Listed?]

Don't see a framework listed? It may work with Tauri without any additional configuration required. Read the [configuration checklist](#configuration-checklist) for any common configurations to check for.

:::

## JavaScript

<CardGrid>
<LinkCard title="Next.js" href="/2/guide/frontend/nextjs" />
<LinkCard title="Nuxt" href="/2/guide/frontend/nuxt" />
<LinkCard title="Qwik" href="/2/guide/frontend/qwik" />
<LinkCard title="SvelteKit" href="/2/guide/frontend/sveltekit" />
<LinkCard title="Vite" href="/2/guide/frontend/vite" />
<LinkCard title="Webpack" href="/2/guide/frontend/webpack" />
</CardGrid>

## Rust

<CardGrid>
<LinkCard title="Leptos" href="/2/guide/frontend/leptos" />
<LinkCard title="Sycamore" href="/2/guide/frontend/sycamore" />
<LinkCard title="Trunk" href="/2/guide/frontend/trunk" />
<LinkCard title="Yew" href="/2/guide/frontend/yew" />
</CardGrid>

## Configuration Checklist

Conceptually Tauri acts as a static web host. You need to provide Tauri with a folder containing some mix of HTML, CSS, Javascript and possibly WASM that can be served to the webview Tauri provides.

Below is a checklist of common scenarios needed to integrate a frontend with Tauri:

{/* TODO: Link to core concept of SSG/SSR, etc. */}
{/* TODO: Link to mobile development server guide */}
{/* TODO: Concept of how to do a client-server relationship? */}

- Use static site generation (SSG). Tauri doesn't officially support server based alternatives (such as SSR).
- For mobile development, a development server of some kind is necessary that can host the frontend on your internal IP.
- Use a proper client-server relationship between your app and your API's (no hybrid solutions with SSR).
7 changes: 7 additions & 0 deletions src/content/docs/2/guide/frontend/leptos.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Leptos
---

import Stub from '@components/Stub.astro';

<Stub />
103 changes: 103 additions & 0 deletions src/content/docs/2/guide/frontend/nextjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Next.js
i18nReady: true
---

import { Tabs, TabItem } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';

Next.js is a React framework. Learn more about Next.js at https://nextjs.org. This guide is accurate as of Next.js 13.4.19.

## Checklist

- Use static exports by setting `output: 'export'`. Tauri doesn't support server-based solutions.
- Use `internal-ip` for mobile compatibility so you can configure `assetPrefix`. This is required so that the server properly resolves assets.
- Use `out/` as `distDir` in `tauri.conf.json`.

## Example Configuration

1. Install `internal-ip` for mobile development:

<CommandTabs
npm="npm install --save-dev internal-ip"
yarn="yarn add -D internal-ip"
pnpm="pnpm add -D internal-ip"
/>

2. Update Tauri configuration:

<Tabs>
<TabItem label="npm">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
<TabItem label="yarn">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn generate",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
<TabItem label="pnpm">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm generate",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
</Tabs>

3. Update Next.js configuration:

```ts
// next.conf.ts
const isProd = process.env.NODE_ENV === 'production';
module.exports = async (phase, { defaultConfig }) => {
let internalHost = null;
// In dev mode we use the internal-ip to serve the assets
if (!isProd) {
const { internalIpV4 } = await import('internal-ip');
internalHost = await internalIpV4();
}
const nextConfig = {
// Ensure Next.js uses SSG instead of SSR
// https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
output: 'export',
// Note: This experimental feature is required to use NextJS Image in SSG mode.
// See https://nextjs.org/docs/messages/export-image-api for different workarounds.
images: {
unoptimized: true,
},
// Configure assetPrefix or else the server won't properly resolve your assets.
assetPrefix: isProd ? null : `http://${internalHost}:3000`,
};
return nextConfig;
};
```
101 changes: 101 additions & 0 deletions src/content/docs/2/guide/frontend/nuxt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Nuxt
i18nReady: true
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

Learn more about Nuxt at https://nuxt.com. This guide is accurate as of Nuxt 3.7.

## Checklist

- Use SSG by setting `ssr: false`. Tauri doesn't support server based solutions.
- Set host to `0.0.0.0`.
- Use `dist/` as `distDir` in `tauri.conf.json`.
- Compile using `nuxi generate`.
- (Optional): Disable telemetry by setting `telemetry: false` in `nuxt.config.ts`.

## Example Configuration

1. Update Tauri configuration:

<Tabs>
<TabItem label="npm">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run generate",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
<TabItem label="yarn">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn generate",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
<TabItem label="pnpm">

```json
// tauri.conf.json
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm generate",
"devPath": "http://localhost:3000",
"distDir": "../dist"
}
}
```

</TabItem>
</Tabs>

2. Update Nuxt configuration:

```ts
export default defineNuxtConfig({
// (optional) Enable the Nuxt devtools
devtools: { enabled: true },
// Enable SSG
ssr: false,
vite: {
// Better support for Tauri CLI output
clearScreen: false,
// Enable environment variables
// Additional environment variables can be found at
// https://tauri.app/2/reference/environment-variables/
envPrefix: ['VITE_', 'TAURI_'],
server: {
// Tauri requires a consistent port
strictPort: true,
// Enables the development server to be discoverable by other devices for mobile development
host: '0.0.0.0',
hmr: {
// Use websocket for mobile hot reloading
protocol: 'ws',
// Make sure it's available on the network
host: '0.0.0.0',
// Use a specific port for hmr
port: 5183,
},
lorenzolewis marked this conversation as resolved.
Show resolved Hide resolved
},
},
});
```
7 changes: 7 additions & 0 deletions src/content/docs/2/guide/frontend/qwik.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Qwik
---

import Stub from '@components/Stub.astro';

<Stub />
7 changes: 7 additions & 0 deletions src/content/docs/2/guide/frontend/svelte.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Svelte
---

import Stub from '@components/Stub.astro';

<Stub />
7 changes: 7 additions & 0 deletions src/content/docs/2/guide/frontend/sycamore.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Sycamore
---

import Stub from '@components/Stub.astro';

<Stub />
Loading