Skip to content

Commit

Permalink
feat: add Sveltekit templates (#200)
Browse files Browse the repository at this point in the history
* feat: πŸ”₯ initial Sveltekit JS template

* feat: πŸ“ add to readme

* feat: πŸ”₯ initial Sveltekit TS template

* fix: 🎨 use a middle dash in name?

* feat: ⚑️ register the templates

* style: ✨ pnpm format

* fix: ✨ match the other boilerplates

* fix: πŸ› add changes

* fix: ⚑️ simplify routes

- Remove unused route group
- Should fix the CI
- Closer to the barebones SK template.

* fix: πŸš‘οΈ apply feedbacks from @amrbashir

* fix: ⚑️ enable CSR

* fix: ⚑️ move to end of lists

* fix: 🎨 remove template comments

* fix: 🎨 missed edits

* favicon.png -> svelte.png

* readme
  • Loading branch information
melMass committed Oct 4, 2022
1 parent dcc3db2 commit 0b09cc1
Show file tree
Hide file tree
Showing 37 changed files with 476 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/svelte-kit-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-tauri-app": minor
"create-tauri-app-js": minor
---

Add `svelte-kit` and `svelte-kit-ts` template.
2 changes: 2 additions & 0 deletions .scripts/generate-templates-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const nodeJsTemplates = [
"preact",
"preact-ts",
"clojurescript",
"svelte-kit",
"svelte-kit-ts",
];

const matrixConfig = [
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Currently supported template presets include:
- `preact-ts`
- `angular`
- `clojurescript`
- `svelte-kit`
- `svelte-kit-ts`

You can use `.` for the project name to scaffold in the current directory.

Expand Down
Binary file added packages/cli/fragments/_assets_/svelte.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"svelte.svelte-vscode",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}
8 changes: 8 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Svelte-Kit + Vite

This template should help get you started developing with Tauri and Svelte-Kit in Vite.

## Recommended IDE Setup

[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).

15 changes: 15 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/_cta_manifest_
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019-2022 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {{pkg_manager_run_command}} dev
beforeBuildCommand = {{pkg_manager_run_command}} build
devPath = http://localhost:1420
distDir = ../build

[files]
vite.svg = static/vite.svg
tauri.svg = static/tauri.svg
svelte.svg = static/svelte.svg
style.css = src/app.css
svelte.png = static/favicon.png
31 changes: 31 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

/build
/.svelte-kit
/package
.env
.env.*
!.env.example
28 changes: 28 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "{{package_name}}",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.1.0"
},
"devDependencies": {
"@sveltejs/kit": "next",
"@sveltejs/adapter-static": "next",
"svelte": "^3.49.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"@tauri-apps/cli": "^1.1.0",
"tslib": "^2.3.1",
"typescript": "^4.8.4",
"vite": "^3.1.0"
}
}
4 changes: 4 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {}
12 changes: 12 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/src/lib/Greet.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/tauri";
let name = "";
let greetMsg = "";
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsg = await invoke("greet", { name });
}
</script>

<div>
<div class="row">
<input id="greet-input" placeholder="Enter a name..." bind:value={name} />
<button on:click={greet}> Greet </button>
</div>
<p>{greetMsg}</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import "../app.css";
</script>

<main class="container">
<slot />
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const prerender = true;
export const csr = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script>
import Greet from "$lib/Greet.svelte";
</script>

<h1>Welcome to Tauri!</h1>

<div class="row">
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo vite" alt="Vite Logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" />
</a>
<a href="https://kit.svelte.dev" target="_blank">
<img src="/svelte.svg" class="logo svelte" alt="Svelte Logo" />
</a>
</div>

<p>Click on the Tauri, Vite, and Svelte logos to learn more.</p>

<div class="row">
<Greet />
</div>

<style>
.logo.vite:hover {
filter: drop-shadow(0 0 2em #747bff);
}
.logo.svelte:hover {
filter: drop-shadow(0 0 2em #ff3e00);
}
</style>
15 changes: 15 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import staticAdapter from "@sveltejs/adapter-static";
import preprocess from "svelte-preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),

kit: {
adapter: staticAdapter(),
},
};

export default config;
17 changes: 17 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
27 changes: 27 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit-ts/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [sveltekit()],

// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
// prevent vite from obscuring rust errors
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
build: {
// Tauri supports es2021
target: ["es2021", "chrome100", "safari13"],
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
});
1 change: 1 addition & 0 deletions packages/cli/fragments/fragment-svelte-kit/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"svelte.svelte-vscode",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}
8 changes: 8 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Svelte-Kit + Vite

This template should help get you started developing with Tauri and Svelte-Kit in Vite.

## Recommended IDE Setup

[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).

15 changes: 15 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/_cta_manifest_
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019-2022 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {{pkg_manager_run_command}} dev
beforeBuildCommand = {{pkg_manager_run_command}} build
devPath = http://localhost:1420
distDir = ../build

[files]
vite.svg = static/vite.svg
tauri.svg = static/tauri.svg
svelte.svg = static/svelte.svg
style.css = src/app.css
svelte.png = static/favicon.png
31 changes: 31 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

/build
/.svelte-kit
/package
.env
.env.*
!.env.example
17 changes: 17 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
27 changes: 27 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "{{package_name}}",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.1.0"
},
"devDependencies": {
"@sveltejs/kit": "next",
"@sveltejs/adapter-static": "next",
"svelte-preprocess": "^4.10.6",
"svelte": "^3.49.0",
"svelte-check": "^2.7.1",
"@tauri-apps/cli": "^1.1.0",
"typescript": "^4.8.4",
"vite": "^3.1.0"
}
}
4 changes: 4 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {}
12 changes: 12 additions & 0 deletions packages/cli/fragments/fragment-svelte-kit/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>

0 comments on commit 0b09cc1

Please sign in to comment.