diff --git a/README.md b/README.md
index d367001..3a7e1cd 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ bin/rails generate inertia:install
This command will:
- Check for Vite Rails and install it if not present
- Ask if you want to use TypeScript
-- Ask you to choose your preferred frontend framework (React, Vue, or Svelte)
+- Ask you to choose your preferred frontend framework (React, Vue, Svelte 4, or Svelte 5)
- Ask if you want to install Tailwind CSS
- Install necessary dependencies
- Set up the application to work with Inertia
@@ -51,7 +51,7 @@ Vite Rails gem successfully installed
Vite Rails successfully installed
Would you like to use TypeScript? (y/n) y
Adding TypeScript support
-What framework do you want to use with Inertia? [react, vue, svelte] (react)
+What framework do you want to use with Inertia? [react, vue, svelte4, svelte] (react)
run npm add @types/react @types/react-dom typescript --silent from "."
Would you like to install Tailwind CSS? (y/n) y
Installing Tailwind CSS
diff --git a/docs/guide/server-side-setup.md b/docs/guide/server-side-setup.md
index da0dc74..e78dbaf 100644
--- a/docs/guide/server-side-setup.md
+++ b/docs/guide/server-side-setup.md
@@ -27,7 +27,7 @@ bin/rails generate inertia:install
This command will:
- Check for Vite Rails and install it if not present
- Ask if you want to use TypeScript
-- Ask you to choose your preferred frontend framework (React, Vue, or Svelte)
+- Ask you to choose your preferred frontend framework (React, Vue, Svelte 4, or Svelte 5)
- Ask if you want to install Tailwind CSS
- Install necessary dependencies
- Set up the application to work with Inertia
@@ -52,7 +52,7 @@ Vite Rails gem successfully installed
Vite Rails successfully installed
Would you like to use TypeScript? (y/n) y
Adding TypeScript support
-What framework do you want to use with Inertia? [react, vue, svelte] (react)
+What framework do you want to use with Inertia? [react, vue, svelte4, svelte] (react)
run npm add @types/react @types/react-dom typescript --silent from "."
Would you like to install Tailwind CSS? (y/n) y
Installing Tailwind CSS
diff --git a/lib/generators/inertia/install/frameworks.yml b/lib/generators/inertia/install/frameworks.yml
index 8868514..6a11dc6 100644
--- a/lib/generators/inertia/install/frameworks.yml
+++ b/lib/generators/inertia/install/frameworks.yml
@@ -47,13 +47,38 @@ vue:
copy_files_js:
"InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue"
+svelte4:
+ inertia_package: "@inertiajs/svelte"
+ packages:
+ - "svelte@4"
+ - "@sveltejs/vite-plugin-svelte@3"
+ packages_ts:
+ - "@tsconfig/svelte@4"
+ - "svelte-check"
+ - "typescript"
+ - "tslib"
+ vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'"
+ vite_plugin_call: "svelte()"
+ copy_files_ts:
+ "InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
+ "tsconfig.json": "tsconfig.json"
+ "tsconfig.node.json": "tsconfig.node.json"
+ "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
+ copy_files_js:
+ "InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
+ copy_files:
+ "svelte.config.js": "svelte.config.js"
+ "../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
+ "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
+ "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
+
svelte:
inertia_package: "@inertiajs/svelte"
packages:
- - "svelte"
- - "@sveltejs/vite-plugin-svelte"
+ - "svelte@5"
+ - "@sveltejs/vite-plugin-svelte@4"
packages_ts:
- - "@tsconfig/svelte"
+ - "@tsconfig/svelte@5"
- "svelte-check"
- "typescript"
- "tslib"
diff --git a/lib/generators/inertia/install/install_generator.rb b/lib/generators/inertia/install/install_generator.rb
index f124183..8315216 100644
--- a/lib/generators/inertia/install/install_generator.rb
+++ b/lib/generators/inertia/install/install_generator.rb
@@ -99,7 +99,7 @@ def install_inertia
insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
end
- gsub_file application_layout.to_s, /
/, "" if framework != "svelte"
+ gsub_file application_layout.to_s, //, "" unless svelte?
else
say_error "Could not find the application layout file. Please add the following tags manually:", :red
say_error "- ..."
@@ -112,7 +112,7 @@ def install_inertia
def install_typescript
say "Adding TypeScript support"
- if framework == "svelte" && inertia_resolved_version.release < Gem::Version.new("1.3.0")
+ if svelte? && inertia_resolved_version.release < Gem::Version.new("1.3.0")
say "WARNING: @inertiajs/svelte < 1.3.0 does not support TypeScript (resolved version: #{inertia_resolved_version}).", :yellow
say "Skipping TypeScript support for @inertiajs/svelte", :yellow
@typescript = false
@@ -270,6 +270,10 @@ def verbose?
options[:verbose]
end
+ def svelte?
+ framework.start_with? "svelte"
+ end
+
def inertia_package
"#{FRAMEWORKS[framework]["inertia_package"]}@#{options[:inertia_version]}"
end
diff --git a/lib/generators/inertia/install/templates/react/inertia.ts b/lib/generators/inertia/install/templates/react/inertia.ts
index b6017fe..4ef3a28 100644
--- a/lib/generators/inertia/install/templates/react/inertia.ts
+++ b/lib/generators/inertia/install/templates/react/inertia.ts
@@ -16,14 +16,14 @@ createInertiaApp({
// progress: false,
resolve: (name) => {
- const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
- return pages[`../pages/${name}.tsx`] as ResolvedComponent
+ const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
+ return pages[`../pages/${name}.tsx`]
// To use a default layout, import the Layout component
// and use the following lines.
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
//
- // const page = pages[`../pages/${name}.tsx`] as ResolvedComponent
+ // const page = pages[`../pages/${name}.tsx`]
// page.default.layout ||= (page) => createElement(Layout, null, page)
// return page
},
diff --git a/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte b/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte
index 96785fe..4c6d294 100644
--- a/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte
+++ b/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte
@@ -3,13 +3,9 @@
import inertiaSvg from '/assets/inertia.svg'
import viteRubySvg from '/assets/vite_ruby.svg'
- export let name
+ let { name } = $props()
- let count = 0
-
- function handleClick() {
- count += 1
- }
+ let count = $state(0)
@@ -34,7 +30,7 @@