Skip to content

Commit

Permalink
feat(create-rsbuild): support for both svelte4 and svelte5 (#3771)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 20, 2024
1 parent 5f60607 commit e1cd766
Show file tree
Hide file tree
Showing 27 changed files with 178 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@examples/svelte",
"name": "@examples/svelte4",
"private": true,
"scripts": {
"dev": "rsbuild dev --open",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { defineConfig } from '@rsbuild/core';
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default defineConfig({
plugins: [pluginSvelte({})],
plugins: [pluginSvelte()],
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/svelte5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"preview": "rsbuild preview"
},
"dependencies": {
"svelte": "^5.0.2"
"svelte": "^5.0.3"
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte5/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { defineConfig } from '@rsbuild/core';
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default defineConfig({
plugins: [pluginSvelte({})],
plugins: [pluginSvelte()],
});
3 changes: 2 additions & 1 deletion packages/create-rsbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ async function getTemplateName({ template }: Argv) {
{ value: 'vue2', label: 'Vue 2' },
{ value: 'lit', label: 'Lit' },
{ value: 'preact', label: 'Preact' },
{ value: 'svelte', label: 'Svelte' },
{ value: 'svelte', label: 'Svelte 5' },
{ value: 'svelte4', label: 'Svelte 4' },
{ value: 'solid', label: 'Solid' },
],
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/create-rsbuild/template-svelte-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"preview": "rsbuild preview"
},
"dependencies": {
"svelte": "^4.2.19"
"svelte": "^5.0.3"
},
"devDependencies": {
"@rsbuild/core": "^1.0.13",
Expand Down
6 changes: 5 additions & 1 deletion packages/create-rsbuild/template-svelte-js/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { mount } from 'svelte';
import App from './App.svelte';
import './index.css';

const app = new App({
const app = mount(App, {
target: document.body,
props: {
name: 'world',
},
});

export default app;
2 changes: 1 addition & 1 deletion packages/create-rsbuild/template-svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"svelte-check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"svelte": "^4.2.19"
"svelte": "^5.0.3"
},
"devDependencies": {
"@rsbuild/core": "^1.0.13",
Expand Down
6 changes: 5 additions & 1 deletion packages/create-rsbuild/template-svelte-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { mount } from 'svelte';
import App from './App.svelte';
import './index.css';

const app = new App({
const app = mount(App, {
target: document.body,
props: {
name: 'world',
},
});

export default app;
17 changes: 17 additions & 0 deletions packages/create-rsbuild/template-svelte4-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "rsbuild-svelte4-js",
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview"
},
"dependencies": {
"svelte": "^4.2.19"
},
"devDependencies": {
"@rsbuild/core": "^1.0.13",
"@rsbuild/plugin-svelte": "^1.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default defineConfig({
plugins: [pluginSvelte()],
});
28 changes: 28 additions & 0 deletions packages/create-rsbuild/template-svelte4-js/src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<main>
<div class="content">
<h1>Rsbuild with Svelte</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
</main>

<style>
.content {
display: flex;
min-height: 100vh;
line-height: 1.1;
text-align: center;
flex-direction: column;
justify-content: center;
}
.content h1 {
font-size: 3.6rem;
font-weight: 700;
}
.content p {
font-size: 1.2rem;
font-weight: 400;
opacity: 0.5;
}
</style>
6 changes: 6 additions & 0 deletions packages/create-rsbuild/template-svelte4-js/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
margin: 0;
color: #fff;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
background-image: linear-gradient(to bottom, #020917, #101725);
}
8 changes: 8 additions & 0 deletions packages/create-rsbuild/template-svelte4-js/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import App from './App.svelte';
import './index.css';

const app = new App({
target: document.body,
});

export default app;
20 changes: 20 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "rsbuild-svelte4-ts",
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview",
"svelte-check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"svelte": "^4.2.19"
},
"devDependencies": {
"@rsbuild/core": "^1.0.13",
"@rsbuild/plugin-svelte": "^1.0.1",
"svelte-check": "^4.0.5",
"typescript": "^5.6.3"
}
}
6 changes: 6 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default defineConfig({
plugins: [pluginSvelte()],
});
28 changes: 28 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<main>
<div class="content">
<h1>Rsbuild with Svelte</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
</main>

<style>
.content {
display: flex;
min-height: 100vh;
line-height: 1.1;
text-align: center;
flex-direction: column;
justify-content: center;
}
.content h1 {
font-size: 3.6rem;
font-weight: 700;
}
.content p {
font-size: 1.2rem;
font-weight: 400;
opacity: 0.5;
}
</style>
2 changes: 2 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@rsbuild/core/types" />
/// <reference types="svelte" />
6 changes: 6 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
margin: 0;
color: #fff;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
background-image: linear-gradient(to bottom, #020917, #101725);
}
8 changes: 8 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import App from './App.svelte';
import './index.css';

const app = new App({
target: document.body,
});

export default app;
19 changes: 19 additions & 0 deletions packages/create-rsbuild/template-svelte4-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"noEmit": true,
"strict": true,
"skipLibCheck": true,
// svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
// to enforce using `import type` instead of `import` for Types.
"verbatimModuleSyntax": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler",
"useDefineForClassFields": true,
"allowImportingTsExtensions": true
},
"include": ["src"]
}
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion website/docs/en/guide/start/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ When creating a project, you can choose from the following templates provided by
| vue2 | [Vue 2](https://v2.vuejs.org/) | TypeScript |
| lit | [Lit](https://lit.dev/) | TypeScript |
| preact | [Preact](https://preactjs.com/) | TypeScript |
| svelte | [Svelte](https://svelte.dev/) | TypeScript |
| svelte | [Svelte 5](https://svelte.dev/) | TypeScript |
| svelte4 | [Svelte 4](https://svelte.dev/) | TypeScript |
| solid | [Solid](https://solidjs.com/) | TypeScript |

### Optional Tools
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/guide/start/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import { PackageManagerTabs } from '@theme';
| vue2 | [Vue 2](https://v2.vuejs.org/) | TypeScript |
| lit | [Lit](https://lit.dev/) | TypeScript |
| preact | [Preact](https://preactjs.com/) | TypeScript |
| svelte | [Svelte](https://svelte.dev/) | TypeScript |
| svelte | [Svelte 5](https://svelte.dev/) | TypeScript |
| svelte4 | [Svelte 4](https://svelte.dev/) | TypeScript |
| solid | [Solid](https://solidjs.com/) | TypeScript |

### 可选工具
Expand Down

0 comments on commit e1cd766

Please sign in to comment.