Skip to content

Commit 4550909

Browse files
authored
chore(demo): Update demo (#67)
1 parent 5a9ebc4 commit 4550909

File tree

5 files changed

+182
-179
lines changed

5 files changed

+182
-179
lines changed

demo/README.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1-
# Svelte + TS + Vite
1+
# @wjfe/n-savant Demo
22

3-
This template should help get you started developing with Svelte and TypeScript in Vite.
3+
This folder contains the demo and tester the author uses while developing the library. It is a **Vite + Svelte + TS** project created with `npm create vite@latest`.
44

5-
## Recommended IDE Setup
5+
## How to Use
66

7-
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
7+
Install dependencies:
88

9-
## Need an official Svelte framework?
10-
11-
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.
12-
13-
## Technical considerations
14-
15-
**Why use this over SvelteKit?**
16-
17-
- It brings its own routing solution which might not be preferable for some users.
18-
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
9+
```bash
10+
npm ci
11+
```
1912

20-
This template contains as little as possible to get started with Vite + TypeScript + 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.
13+
Then, you can do one of 2 options:
2114

22-
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.
15+
1. Install the routing library: `npm i @wjfe/n-savant`
16+
2. Build the package and link it with NPM.
2317

24-
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
18+
The first option simply pulls the latest version from `npmjs.org`. Not good for development of the library.
2519

26-
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.
20+
For the second option, move your terminal's current directory to the repository's root folder, then:
2721

28-
**Why include `.vscode/extensions.json`?**
22+
```bash
23+
npm run prepack && npm link
24+
```
2925

30-
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.
26+
Now move to the `/demo` folder and complete the link:
3127

32-
**Why enable `allowJs` in the TS template?**
28+
```bash
29+
npm link @wjfe/n-savant
30+
```
3331

34-
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
32+
You are ready to run the development server:
3533

36-
**Why is HMR not preserving my local component state?**
34+
```bash
35+
npm run dev
36+
```
3737

38-
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/rixo/svelte-hmr#svelte-hmr).
38+
Use the second option when developing/manipulating the library's code to see the effects in the demo project. It does require you to run `npm run prepack` after the changes are made, though. The link established by the `npm` CLI tool is based on the created `dist/` folder, not the `src/` folder.
3939

40-
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
40+
### Gotcha's
4141

42-
```ts
43-
// store.ts
44-
// An extremely simple external store
45-
import { writable } from 'svelte/store'
46-
export default writable(0)
47-
```
42+
+ NPM can only handle **one** linked library.
43+
+ A project using a linked library (the demo project in this case), will require re-linking if you perform any action on the installed packages, such as `npm up`, `npm i`, `npm remove`. Basically, any command that alters the contents of `node_modules/` will break the link. Re-establish the link after meddling with `node_modules/`.
44+
+ Potentially a bug in Vite: HMR will work the first time you repackage, but will not work on subsequent repackage operations. Use the `r` command in the running Vite dev server to restart it.
45+
+ Depending on the change you make in the library, even with HMR you'll need to restart the Vite server or refresh the demo page because global state that is set during the call to `init()` is lost.

0 commit comments

Comments
 (0)