feat(create-app): add 'svelte' and 'svelte-ts' options#2537
Merged
yyx990803 merged 1 commit intovitejs:mainfrom Mar 16, 2021
Merged
feat(create-app): add 'svelte' and 'svelte-ts' options#2537yyx990803 merged 1 commit intovitejs:mainfrom
yyx990803 merged 1 commit intovitejs:mainfrom
Conversation
patak-cat
approved these changes
Mar 16, 2021
Member
patak-cat
left a comment
There was a problem hiding this comment.
Looks great! Just tested and they worked like a charm.
Thanks for the detailed explanation.
Once SvelteKit is released, is the idea to move from @svitejs/vite-plugin-svelte to https://github.com/sveltejs/kit/tree/master/packages/vite-plugin-svelte ?
Member
Author
|
There's currently an open issue (sveltejs/kit#497) regarding whether we'll end up using |
This was referenced Mar 16, 2021
Closed
Closed
This was referenced Mar 18, 2021
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
svelteandsvelte-tstemplates.Why Svelte?
I believe there is interest in having Svelte as a first-class
create-apptemplate, based from previously opened issues (#2209) and prior communication with Vite maintainers in the official Discord server.Why not SvelteKit?
vite devandvite buildwouldn't work in a SvelteKit environment, for example.The templates in this PR contain 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-apptemplates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.Should they 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.
Technical considerations
Why
globals.d.tsinstead ofcompilerOptions.typesinsidejsconfig.jsonortsconfig.json?Setting
compilerOptions.typesshuts 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 addingsvelteandvite/clienttype 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
checkJsin the JS template?I believe most cases of changing the types of variables in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should the user like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration.
Why enable
allowJsin the TS template?While
allowJs: falsewould indeed prevent the use of.jsfiles in the project, it does not prevent the use of JavaScript syntax in.sveltefiles. In addition, it would forcecheckJs: false, bringing the user the worst of both worlds: not being able to guarantee their entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, I believe there are valid use cases in which a mixed codebase may be relevant.Why include an HMR store, instead of just using local state?
This allows us to take full advantage of HMR. While
vite-plugin-sveltedoes support an option to enable local state saving, it is not recommended, as it is an inherently difficult problem to solve without external stores. Changes to the local state definition can make it unclear what the intended HMR behavior is. Admittedly, the code is a bit more advanced and takes advantage of some frameworky features of Vite, but I believe this is a better out-of-the-box experience and does not add unnecessary complexity.