diff --git a/e2e/init-svelte-4.sh b/e2e/init-svelte-4.sh new file mode 100755 index 0000000..c742094 --- /dev/null +++ b/e2e/init-svelte-4.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +npm init vite +# select svelte, js and name "svelte-4" +cd svelte-4 + +npm install +# apply all steps from https://github.com/rossyman/svelte-add-jest/blob/main/preset.ts + +cd .. diff --git a/e2e/svelte-4/.gitignore b/e2e/svelte-4/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/e2e/svelte-4/.gitignore @@ -0,0 +1,24 @@ +# 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? diff --git a/e2e/svelte-4/.vscode/extensions.json b/e2e/svelte-4/.vscode/extensions.json new file mode 100644 index 0000000..bdef820 --- /dev/null +++ b/e2e/svelte-4/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["svelte.svelte-vscode"] +} diff --git a/e2e/svelte-4/README.md b/e2e/svelte-4/README.md new file mode 100644 index 0000000..382941e --- /dev/null +++ b/e2e/svelte-4/README.md @@ -0,0 +1,47 @@ +# Svelte + Vite + +This template should help get you started developing with Svelte in Vite. + +## Recommended IDE Setup + +[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). + +## Need an official Svelte framework? + +Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. + +## Technical considerations + +**Why use this over SvelteKit?** + +- It brings its own routing solution which might not be preferable for some users. +- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. + +This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. + +Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate. + +**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** + +Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. + +**Why include `.vscode/extensions.json`?** + +Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project. + +**Why enable `checkJs` in the JS template?** + +It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration. + +**Why is HMR not preserving my local component state?** + +HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state). + +If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. + +```js +// store.js +// An extremely simple external store +import { writable } from 'svelte/store' +export default writable(0) +``` diff --git a/e2e/svelte-4/index.html b/e2e/svelte-4/index.html new file mode 100644 index 0000000..feaf27c --- /dev/null +++ b/e2e/svelte-4/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + Svelte + + +
+ + + diff --git a/e2e/svelte-4/jsconfig.json b/e2e/svelte-4/jsconfig.json new file mode 100644 index 0000000..5696a2d --- /dev/null +++ b/e2e/svelte-4/jsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "moduleResolution": "bundler", + "target": "ESNext", + "module": "ESNext", + /** + * 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, + /** + * To have warnings / errors of the Svelte compiler at the + * correct position, enable source maps by default. + */ + "sourceMap": true, + "esModuleInterop": true, + "skipLibCheck": true, + /** + * Typecheck JS in `.svelte` and `.js` files by default. + * Disable this if you'd like to use dynamic types. + */ + "checkJs": true + }, + /** + * Use global.d.ts instead of compilerOptions.types + * to avoid limiting type declarations. + */ + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/e2e/svelte-4/package.json b/e2e/svelte-4/package.json new file mode 100644 index 0000000..39568e0 --- /dev/null +++ b/e2e/svelte-4/package.json @@ -0,0 +1,16 @@ +{ + "name": "svelte-4", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^3.0.2", + "svelte": "^4.2.12", + "vite": "^5.2.0" + } +} diff --git a/e2e/svelte-4/public/vite.svg b/e2e/svelte-4/public/vite.svg new file mode 100644 index 0000000..e7b8dfb --- /dev/null +++ b/e2e/svelte-4/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/e2e/svelte-4/src/App.svelte b/e2e/svelte-4/src/App.svelte new file mode 100644 index 0000000..1f31354 --- /dev/null +++ b/e2e/svelte-4/src/App.svelte @@ -0,0 +1,47 @@ + + +
+
+ + + + + + +
+

Vite + Svelte

+ +
+ +
+ +

+ Check out SvelteKit, the official Svelte app framework powered by Vite! +

+ +

+ Click on the Vite and Svelte logos to learn more +

+
+ + diff --git a/e2e/svelte-4/src/app.css b/e2e/svelte-4/src/app.css new file mode 100644 index 0000000..617f5e9 --- /dev/null +++ b/e2e/svelte-4/src/app.css @@ -0,0 +1,79 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +.card { + padding: 2em; +} + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/e2e/svelte-4/src/assets/svelte.svg b/e2e/svelte-4/src/assets/svelte.svg new file mode 100644 index 0000000..c5e0848 --- /dev/null +++ b/e2e/svelte-4/src/assets/svelte.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/e2e/svelte-4/src/lib/Counter.svelte b/e2e/svelte-4/src/lib/Counter.svelte new file mode 100644 index 0000000..e45f903 --- /dev/null +++ b/e2e/svelte-4/src/lib/Counter.svelte @@ -0,0 +1,10 @@ + + + diff --git a/e2e/svelte-4/src/main.js b/e2e/svelte-4/src/main.js new file mode 100644 index 0000000..8a909a1 --- /dev/null +++ b/e2e/svelte-4/src/main.js @@ -0,0 +1,8 @@ +import './app.css' +import App from './App.svelte' + +const app = new App({ + target: document.getElementById('app'), +}) + +export default app diff --git a/e2e/svelte-4/src/vite-env.d.ts b/e2e/svelte-4/src/vite-env.d.ts new file mode 100644 index 0000000..4078e74 --- /dev/null +++ b/e2e/svelte-4/src/vite-env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/e2e/svelte-4/svelte.config.js b/e2e/svelte-4/svelte.config.js new file mode 100644 index 0000000..b0683fd --- /dev/null +++ b/e2e/svelte-4/svelte.config.js @@ -0,0 +1,7 @@ +import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' + +export default { + // Consult https://svelte.dev/docs#compile-time-svelte-preprocess + // for more information about preprocessors + preprocess: vitePreprocess(), +} diff --git a/e2e/svelte-4/vite.config.js b/e2e/svelte-4/vite.config.js new file mode 100644 index 0000000..d701969 --- /dev/null +++ b/e2e/svelte-4/vite.config.js @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import { svelte } from '@sveltejs/vite-plugin-svelte' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [svelte()], +})