Skip to content

Commit 5a002c7

Browse files
authored
Feat: open file inspector (#322)
* feat: add dev mode inspector to open editor at location that defines dom element * wip: add options to inspector, improve inspector ux * wip: deep config merge, more inspector options, automatic sveltekit support * wip: add custom cursor, update toggle, cleanup Inspector, add docs * chore: add changeset and revert target change * docs: add trigger description to docs * chore: restore docs headline * fix: account for experimental possibly being undefined due to new merging; update browser select for testing * fix: remove hold, skip over node_modules locations, cleanup, docs * feat: generic combo handling, hold disabled by default, pos and visibility options for toggle, docs * fix: restore array overwrite behavior in config merge change to avoid a breaking change * fix: use os dependant default combo to minimize clashes with native behavior
1 parent a299b87 commit 5a002c7

File tree

14 files changed

+661
-438
lines changed

14 files changed

+661
-438
lines changed

.changeset/green-buttons-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
use deepmerge utility to merge inline config and svelte.config.js

.changeset/sweet-birds-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': minor
3+
---
4+
5+
Add experimental Svelte Inspector to quickly jump to code from your browser.

docs/config.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,58 @@ export default defineConfig({
258258
]
259259
});
260260
```
261+
262+
### inspector
263+
264+
- **Type:**`InspectorOptions | boolean`
265+
266+
```ts
267+
interface InspectorOptions {
268+
/**
269+
* define a key combo to toggle inspector,
270+
* @default 'control-shift' on windows, 'meta-shift' on other os
271+
*
272+
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
273+
* examples: control-shift, control-o, control-alt-s meta-x control-meta
274+
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
275+
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
276+
*/
277+
toggleKeyCombo?: string;
278+
279+
/**
280+
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
281+
* @default false
282+
*/
283+
holdMode?: boolean;
284+
285+
/**
286+
* when to show the toggle button
287+
* @default 'active'
288+
*/
289+
showToggleButton?: 'always' | 'active' | 'never';
290+
291+
/**
292+
* where to display the toggle button
293+
* @default top-right
294+
*/
295+
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
296+
297+
/**
298+
* inject custom styles when inspector is active
299+
*/
300+
customStyles?: boolean;
301+
302+
/**
303+
* append an import to the module id ending with `appendTo` instead of adding a script into body
304+
* useful for frameworks that do not support trannsformIndexHtml hook
305+
*
306+
* WARNING: only set this if you know exactly what it does.
307+
* Regular users of vite-plugin-svelte or SvelteKit do not need it
308+
*/
309+
appendTo?: string;
310+
}
311+
```
312+
313+
Set to `true` or customized `InspectorOptions` to enable svelte inspector during development.
314+
315+
When enabled, inspector mode shows you the file location where the element under cursor is defined and you can click to quickly open your code editor at this location.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
2-
"compilerOptions": {
3-
"baseUrl": ".",
4-
"paths": {
5-
"$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"],
6-
"$lib/*": ["src/lib/*"]
7-
}
8-
},
2+
"extends": "./.svelte-kit/tsconfig.json",
93
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
104
}

packages/playground/kit-demo-app/svelte.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const config = {
1212
vite: {
1313
css: { devSourcemap: true }
1414
}
15+
},
16+
experimental: {
17+
inspector: true
1518
}
1619
};
1720

packages/vite-plugin-svelte/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"import": "./dist/index.js",
2020
"require": "./dist/index.cjs"
2121
},
22-
"./package.json": "./package.json"
22+
"./package.json": "./package.json",
23+
"./src/ui/*": "./src/ui/*"
2324
},
2425
"scripts": {
2526
"dev": "pnpm run build:ci -- --sourcemap --watch src",
@@ -47,6 +48,7 @@
4748
"dependencies": {
4849
"@rollup/pluginutils": "^4.2.1",
4950
"debug": "^4.3.4",
51+
"deepmerge": "^4.2.2",
5052
"kleur": "^4.1.4",
5153
"magic-string": "^0.26.1",
5254
"svelte-hmr": "^0.14.11"

0 commit comments

Comments
 (0)