diff --git a/template/{{ part_dir }}/package.json.jinja b/template/{{ part_dir }}/package.json.jinja index 1d83f87..ed80089 100644 --- a/template/{{ part_dir }}/package.json.jinja +++ b/template/{{ part_dir }}/package.json.jinja @@ -3,6 +3,10 @@ "version": "0.0.1", "private": true, "type": "module", + "imports": { + "#lib": "./src/lib/index.js", + "#lib/*": "./src/lib/*" + }, "scripts": { "build": "vite build", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", @@ -20,19 +24,19 @@ }, "devDependencies": { {%- set deps = { - "@sveltejs/kit": "^2.63.0", + "@sveltejs/kit": "^3.0.1", "@sveltejs/vite-plugin-svelte": "^7.1.2", "@tailwindcss/vite": "^4.3.0", "@types/bun": "^1.3.0", - "svelte": "^5.56.1", - "svelte-check": "^4.6.0", + "svelte": "^5.57.1", + "svelte-check": "^4.7.6", "tailwindcss": "^4.3.0", "typescript": "^6.0.3", "vite": "^8.0.16", } -%} {%- if linter == 'biome' %}{% set _ = deps.update({ - "@biomejs/biome": "2.5.13", - "ultracite": "7.12.0", + "@biomejs/biome": "^2.5.15", + "ultracite": "^7.12.4", }) %}{% else %}{% set _ = deps.update({ "@eslint/compat": "^2.1.1", "@eslint/js": "^10.0.1", @@ -45,7 +49,7 @@ "prettier-plugin-tailwindcss": "^0.8.1", "typescript-eslint": "^8.71.1", }) %}{% endif -%} -{%- if frontend_adapter == 'bun' %}{% set _ = deps.update({"svelte-adapter-bun": "^1.0.1"}) %}{% else %}{% set _ = deps.update({"@sveltejs/adapter-static": "^3.0.10"}) %}{% endif -%} +{%- if frontend_adapter == 'bun' %}{% set _ = deps.update({"@sveltejs/adapter-bun": "^1.0.0"}) %}{% else %}{% set _ = deps.update({"@sveltejs/adapter-static": "^4.0.0"}) %}{% endif -%} {%- if ui_library == 'shadcn' %}{% set _ = deps.update({ "@internationalized/date": "^3.12.0", "@lucide/svelte": "^1.23.0", diff --git a/template/{{ part_dir }}/src/env.ts b/template/{{ part_dir }}/src/env.ts new file mode 100644 index 0000000..f6966a0 --- /dev/null +++ b/template/{{ part_dir }}/src/env.ts @@ -0,0 +1,5 @@ +import { defineEnvVars } from "@sveltejs/kit/env"; + +export const variables = defineEnvVars({ + PUBLIC_API_BASE_URL: { public: true, schema: (input) => input ?? "/api" }, +}); diff --git a/template/{{ part_dir }}/src/lib/api/client.ts b/template/{{ part_dir }}/src/lib/api/client.ts index a2e8ceb..423b466 100644 --- a/template/{{ part_dir }}/src/lib/api/client.ts +++ b/template/{{ part_dir }}/src/lib/api/client.ts @@ -1,6 +1,6 @@ -import { env } from "$env/dynamic/public"; +import { PUBLIC_API_BASE_URL } from "$app/env/public"; -const BASE = env.PUBLIC_API_BASE_URL ?? "/api"; +const BASE = PUBLIC_API_BASE_URL; export class ApiError extends Error { status: number; diff --git a/template/{{ part_dir }}/src/lib/index.ts.jinja b/template/{{ part_dir }}/src/lib/index.ts.jinja index 5830bbc..9451489 100644 --- a/template/{{ part_dir }}/src/lib/index.ts.jinja +++ b/template/{{ part_dir }}/src/lib/index.ts.jinja @@ -1,3 +1,3 @@ -// place files you want to import through the `$lib` alias in this folder. +// place files you want to import through the `#lib` alias in this folder. {% if linter == 'biome' %}// biome-ignore-all lint/suspicious/noEmptySource: temporary {% endif %} \ No newline at end of file diff --git a/template/{{ part_dir }}/svelte.config.js.jinja b/template/{{ part_dir }}/svelte.config.js.jinja deleted file mode 100644 index 4fa3b8c..0000000 --- a/template/{{ part_dir }}/svelte.config.js.jinja +++ /dev/null @@ -1,36 +0,0 @@ -{% if frontend_adapter == 'bun' -%} -import adapter from "svelte-adapter-bun"; - -/** @type {import('@sveltejs/kit').Config} */ -const config = { - compilerOptions: { - runes: ({ filename }) => -{% if linter == 'biome' %} // biome-ignore lint/performance/useTopLevelRegex: svelte default behaviour -{% endif %} filename.split(/[/\\]/).includes("node_modules") ? undefined : true, - }, - kit: { - adapter: adapter(), - }, -}; - -export default config; -{%- else -%} -import adapter from "@sveltejs/adapter-static"; -import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; - -/** @type {import('@sveltejs/kit').Config} */ -const config = { - kit: { - adapter: adapter({ - assets: "build", - fallback: "index.html", - pages: "build", - precompress: false, - strict: false, - }), - }, - preprocess: vitePreprocess(), -}; - -export default config; -{%- endif %} diff --git a/template/{{ part_dir }}/tsconfig.json.jinja b/template/{{ part_dir }}/tsconfig.json.jinja index c7b9df5..f82bdf7 100644 --- a/template/{{ part_dir }}/tsconfig.json.jinja +++ b/template/{{ part_dir }}/tsconfig.json.jinja @@ -1,20 +1,9 @@ { - "extends": "./.svelte-kit/tsconfig.json", + "extends": "$app/tsconfig", "compilerOptions": { "rewriteRelativeImportExtensions": true, - "allowJs": true, - "checkJs": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, "sourceMap": true, - "strict": true, - "moduleResolution": "bundler" - } - // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias - // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files - // - // To make changes to top-level options such as include and exclude, we recommend extending - // the generated config; see https://svelte.dev/docs/kit/configuration#typescript + "strict": true + }, + "include": ["src", "vite.config.ts"] } diff --git a/template/{{ part_dir }}/vite.config.ts b/template/{{ part_dir }}/vite.config.ts deleted file mode 100644 index b3dca69..0000000 --- a/template/{{ part_dir }}/vite.config.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { sveltekit } from "@sveltejs/kit/vite"; -import tailwindcss from "@tailwindcss/vite"; -import { defineConfig } from "vite"; - -const allowedHosts = process.env.ALLOWED_HOSTS - ? process.env.ALLOWED_HOSTS.split(",") - : undefined; - -export default defineConfig({ - plugins: [tailwindcss(), sveltekit()], - server: { - allowedHosts, - proxy: { - "/api": { - changeOrigin: true, - target: process.env.API_PROXY_TARGET ?? "http://localhost:8080", - }, - }, - }, -}); diff --git a/template/{{ part_dir }}/vite.config.ts.jinja b/template/{{ part_dir }}/vite.config.ts.jinja new file mode 100644 index 0000000..e960015 --- /dev/null +++ b/template/{{ part_dir }}/vite.config.ts.jinja @@ -0,0 +1,51 @@ +{% if frontend_adapter == 'bun' -%} +import adapter from "@sveltejs/adapter-bun"; +import { sveltekit } from "@sveltejs/kit/vite"; +import tailwindcss from "@tailwindcss/vite"; +import { defineConfig } from "vite"; + +const PATH_SEP = /[/\\]/; +{%- else -%} +import adapter from "@sveltejs/adapter-static"; +import { sveltekit } from "@sveltejs/kit/vite"; +import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; +import tailwindcss from "@tailwindcss/vite"; +import { defineConfig } from "vite"; +{%- endif %} + +const allowedHosts = process.env.ALLOWED_HOSTS + ? process.env.ALLOWED_HOSTS.split(",") + : undefined; + +export default defineConfig({ + plugins: [ + tailwindcss(), + sveltekit({ +{%- if frontend_adapter == 'bun' %} + adapter: adapter(), + compilerOptions: { + runes: ({ filename }) => + filename.split(PATH_SEP).includes("node_modules") ? undefined : true, + }, +{%- else %} + adapter: adapter({ + assets: "build", + fallback: "index.html", + pages: "build", + precompress: false, + strict: false, + }), + preprocess: [vitePreprocess()], +{%- endif %} + }), + ], + server: { + allowedHosts, + proxy: { + "/api": { + changeOrigin: true, + target: process.env.API_PROXY_TARGET ?? "http://localhost:8080", + }, + }, + }, +}); diff --git a/template/{{ part_dir }}/{% if linter == 'biome' %}biome.jsonc{% endif %}.jinja b/template/{{ part_dir }}/{% if linter == 'biome' %}biome.jsonc{% endif %}.jinja index efe1c6e..514d228 100644 --- a/template/{{ part_dir }}/{% if linter == 'biome' %}biome.jsonc{% endif %}.jinja +++ b/template/{{ part_dir }}/{% if linter == 'biome' %}biome.jsonc{% endif %}.jinja @@ -21,6 +21,7 @@ "includes": ["**/*.svelte"], "linter": { "rules": { + "a11y": { "useAnchorContent": "off" }, "style": { "useFilenamingConvention": { "level": "error", diff --git a/template/{{ part_dir }}/{% if linter == 'eslint' %}eslint.config.js{% endif %}.jinja b/template/{{ part_dir }}/{% if linter == 'eslint' %}eslint.config.js{% endif %}.jinja index 049832f..9cb50a8 100644 --- a/template/{{ part_dir }}/{% if linter == 'eslint' %}eslint.config.js{% endif %}.jinja +++ b/template/{{ part_dir }}/{% if linter == 'eslint' %}eslint.config.js{% endif %}.jinja @@ -6,10 +6,20 @@ import svelte from "eslint-plugin-svelte"; import { defineConfig } from "eslint/config"; import globals from "globals"; import ts from "typescript-eslint"; -import svelteConfig from "./svelte.config.js"; const gitignorePath = fileURLToPath(new URL("./.gitignore", import.meta.url)); +{% if frontend_adapter == 'bun' -%} +const svelteConfig = { + compilerOptions: { + runes: ({ filename }) => + filename.split(/[/\\]/).includes("node_modules") ? undefined : true, + }, +}; +{%- else -%} +const svelteConfig = {}; +{%- endif %} + export default defineConfig( includeIgnoreFile(gitignorePath), js.configs.recommended, diff --git a/template/{{ part_dir }}/{% if serve != 'api' %}Dockerfile{% endif %}.jinja b/template/{{ part_dir }}/{% if serve != 'api' %}Dockerfile{% endif %}.jinja index c2512dc..583baa5 100644 --- a/template/{{ part_dir }}/{% if serve != 'api' %}Dockerfile{% endif %}.jinja +++ b/template/{{ part_dir }}/{% if serve != 'api' %}Dockerfile{% endif %}.jinja @@ -1,5 +1,5 @@ {% if frontend_adapter == 'bun' -%} -FROM oven/bun:alpine AS deps +FROM oven/bun:1-alpine AS deps ENV TERM=xterm-256color ENV COLORTERM=truecolor @@ -22,7 +22,7 @@ RUN bun --bun svelte-kit sync RUN bun --bun run build -FROM oven/bun:alpine AS runtime +FROM oven/bun:1-alpine AS runtime ENV NODE_ENV=production # The cache mount only holds files; without the variable bun caches into @@ -42,7 +42,7 @@ EXPOSE 3000 ENTRYPOINT ["bun"] CMD ["build/index.js"] {%- else -%} -FROM oven/bun:alpine AS deps +FROM oven/bun:1-alpine AS deps ENV TERM=xterm-256color ENV COLORTERM=truecolor @@ -63,7 +63,7 @@ RUN bun --bun svelte-kit sync RUN bun run build -FROM oven/bun:alpine AS runtime +FROM oven/bun:1-alpine AS runtime ENV NODE_ENV=production