Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cecb98484 | ||
|
|
d4b7683147 |
@@ -2,6 +2,26 @@
|
|||||||
|
|
||||||
This template should help get you started developing with Svelte in Vite.
|
This template should help get you started developing with Svelte in Vite.
|
||||||
|
|
||||||
|
## Running the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running tests
|
||||||
|
|
||||||
|
- **Watch mode** (re-runs on file changes):
|
||||||
|
`npm run test`
|
||||||
|
|
||||||
|
- **Single run** (CI-friendly):
|
||||||
|
`npm run test:run`
|
||||||
|
|
||||||
|
- **Coverage report**:
|
||||||
|
`npm run test:coverage`
|
||||||
|
|
||||||
|
Tests use Vitest and `@testing-library/svelte`. Place test files next to the code they cover (e.g. `Component.test.js` beside `Component.svelte`) or in a `__tests__` directory.
|
||||||
|
|
||||||
## Recommended IDE Setup
|
## Recommended IDE Setup
|
||||||
|
|
||||||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||||
|
|||||||
+9
-5
@@ -1,9 +1,13 @@
|
|||||||
import { mount } from 'svelte'
|
|
||||||
import './app.css'
|
import './app.css'
|
||||||
import App from './App.svelte'
|
|
||||||
|
|
||||||
const app = mount(App, {
|
// Only load and mount the app in a real browser (document + mount available).
|
||||||
target: document.getElementById('app'),
|
// Avoids "mount() is not available on the server" when the bundle runs in SSR/workers.
|
||||||
})
|
let app = null
|
||||||
|
const target = typeof document !== 'undefined' && document.getElementById('app')
|
||||||
|
if (target) {
|
||||||
|
const { mount } = await import('svelte')
|
||||||
|
const { default: App } = await import('./App.svelte')
|
||||||
|
app = mount(App, { target })
|
||||||
|
}
|
||||||
|
|
||||||
export default app
|
export default app
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|||||||
export default defineConfig(({ mode }) => ({
|
export default defineConfig(({ mode }) => ({
|
||||||
plugins: [svelte()],
|
plugins: [svelte()],
|
||||||
resolve: {
|
resolve: {
|
||||||
// Use browser Svelte build in tests so mount() is available (avoid "lifecycle_function_unavailable")
|
// Prefer browser Svelte build so mount() is available (avoid "lifecycle_function_unavailable" on server/workers)
|
||||||
conditions: mode === 'test' ? ['browser'] : [],
|
conditions: ['browser'],
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
include: ['src/**/*.{test,spec}.{js,ts}'],
|
include: ['src/**/*.{test,spec}.{js,ts}'],
|
||||||
|
|||||||
Reference in New Issue
Block a user