Skip to content

Commit 2132b5f

Browse files
authored
fix: use different way to resolve inspector path (see #330) (#332)
* fix: use different way to resolve inspector path (see #330) * test: add tests for inspector with kit and vite templates * fix: use import.meta.url to determine inspector path * fix: prefix windows paths with /@fs/ * fix: windows path handling * fix: inline svg and read inspector file ourselves to prevent fs.allow interfering
1 parent ece05a9 commit 2132b5f

File tree

22 files changed

+345
-46
lines changed

22 files changed

+345
-46
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ module.exports = {
6969
'no-console': 'error'
7070
}
7171
},
72+
{
73+
files: ['packages/vite-plugin-svelte/src/ui/inspector/load-inspector.js'],
74+
env: {
75+
browser: true
76+
}
77+
},
7278
{
7379
files: ['packages/e2e-tests/**', 'packages/playground/**'],
7480
rules: {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getEl, getText, isBuild } from '../../testUtils';
2+
3+
describe('inspector-kit', () => {
4+
it('should render page', async () => {
5+
expect(await getText('h1')).toBe('Hello Inspector!');
6+
});
7+
if (!isBuild) {
8+
it('should show inspector toggle during dev', async () => {
9+
expect(await getEl('.svelte-inspector-toggle')).not.toBe(null);
10+
});
11+
} else {
12+
it('should not show inspector toggle during preview', async () => {
13+
expect(await getEl('.svelte-inspector-toggle')).toBe(null);
14+
});
15+
}
16+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "e2e-tests-inspector-kit",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "svelte-kit dev",
7+
"build": "svelte-kit build",
8+
"package": "svelte-kit package",
9+
"preview": "svelte-kit preview"
10+
},
11+
"devDependencies": {
12+
"@sveltejs/kit": "^1.0.0-next.326",
13+
"svelte": "^3.48.0"
14+
},
15+
"type": "module",
16+
"pnpm": {
17+
"overrides": {
18+
"@sveltejs/vite-plugin-svelte": "workspace:*"
19+
}
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
%svelte.head%
7+
</head>
8+
<body>
9+
<div>%svelte.body%</div>
10+
</body>
11+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello Inspector!</h1>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('@sveltejs/kit').Config} */
2+
const config = {
3+
kit: {},
4+
experimental: {
5+
inspector: {
6+
showToggleButton: 'always'
7+
}
8+
}
9+
};
10+
11+
export default config;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Svelte + Vite
2+
3+
This template should help get you started developing with Svelte in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
8+
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.
19+
`vite dev` and `vite build` wouldn't work in a SvelteKit environment, for example.
20+
21+
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.
22+
23+
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.
24+
25+
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
26+
27+
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.
28+
29+
**Why include `.vscode/extensions.json`?**
30+
31+
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.
32+
33+
**Why enable `checkJs` in the JS template?**
34+
35+
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.
36+
37+
**Why is HMR not preserving my local component state?**
38+
39+
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).
40+
41+
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
42+
43+
```js
44+
// store.js
45+
// An extremely simple external store
46+
import { writable } from 'svelte/store';
47+
export default writable(0);
48+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getEl, getText, isBuild } from '../../testUtils';
2+
3+
describe('inspector-vite', () => {
4+
it('should render page', async () => {
5+
expect(await getText('h1')).toBe('Hello Inspector!');
6+
});
7+
if (!isBuild) {
8+
it('should show inspector toggle during dev', async () => {
9+
expect(await getEl('.svelte-inspector-toggle')).not.toBe(null);
10+
});
11+
} else {
12+
it('should not show inspector toggle during preview', async () => {
13+
expect(await getEl('.svelte-inspector-toggle')).toBe(null);
14+
});
15+
}
16+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
<script type="module" src="/src/main.js"></script>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)