@sveltejs/vite-plugin-svelte 1.0.0-next.43 → 1.0.0-next.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -38
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/src/ui/inspector/Inspector.svelte +24 -8
- package/src/ui/inspector/{load-inspector.ts → load-inspector.js} +1 -2
- package/src/ui/inspector/plugin.ts +36 -31
- package/src/ui/inspector/icon.svg +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.44",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -62,16 +62,15 @@
|
|
|
62
62
|
"@types/debug": "^4.1.7",
|
|
63
63
|
"@types/diff-match-patch": "^1.0.32",
|
|
64
64
|
"diff-match-patch": "^1.0.5",
|
|
65
|
-
"esbuild": "^0.14.
|
|
66
|
-
"rollup": "^2.
|
|
67
|
-
"svelte": "^3.
|
|
68
|
-
"tsup": "^5.12.
|
|
65
|
+
"esbuild": "^0.14.38",
|
|
66
|
+
"rollup": "^2.72.1",
|
|
67
|
+
"svelte": "^3.48.0",
|
|
68
|
+
"tsup": "^5.12.7",
|
|
69
69
|
"vite": "^2.9.8"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
|
-
"dev": "pnpm
|
|
72
|
+
"dev": "pnpm build:ci --sourcemap --watch src",
|
|
73
73
|
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting --target node14",
|
|
74
|
-
"build": "pnpm
|
|
75
|
-
}
|
|
76
|
-
"readme": "# @sveltejs/vite-plugin-svelte\n\nThe official [Svelte](https://svelte.dev) plugin for [Vite](https://vitejs.dev).\n\n## Usage\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport { svelte } from '@sveltejs/vite-plugin-svelte';\n\nexport default defineConfig({\n plugins: [\n svelte({\n /* plugin options */\n })\n ]\n});\n```\n\n## Documentation\n\n- [Plugin options](../../docs/config.md)\n- [FAQ](../../docs/faq.md)\n\n## License\n\n[MIT](./LICENSE)\n"
|
|
74
|
+
"build": "pnpm build:ci --dts --sourcemap"
|
|
75
|
+
}
|
|
77
76
|
}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
// do not use TS here so that this component works in non-ts projects too
|
|
3
3
|
import { onMount } from 'svelte';
|
|
4
|
-
// @ts-expect-error virtual import is resolved by vite-plugin-svelte-inspector
|
|
5
|
-
// eslint-disable-next-line node/no-missing-import
|
|
6
|
-
import icon from 'virtual:svelte-inspector:icon.svg';
|
|
7
|
-
// @ts-expect-error virtual import is resolved by vite-plugin-svelte-inspector
|
|
8
4
|
// eslint-disable-next-line node/no-missing-import
|
|
9
5
|
import options from 'virtual:svelte-inspector-options';
|
|
10
6
|
const toggle_combo = options.toggleKeyCombo?.toLowerCase().split('-');
|
|
11
7
|
|
|
12
8
|
let enabled = false;
|
|
13
9
|
|
|
10
|
+
const icon = `data:image/svg+xml;base64,${btoa(
|
|
11
|
+
`
|
|
12
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="25" viewBox="0 0 107 128">
|
|
13
|
+
<title>svelte-inspector-logo</title>
|
|
14
|
+
<path d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157" style="fill:#ff3e00"/><path d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287" style="fill:#fff"/>
|
|
15
|
+
<polygon points="0,0 15,40 40,20" stroke="#ff3e00" fill="#ff3e00"></polygon>
|
|
16
|
+
</svg>
|
|
17
|
+
`
|
|
18
|
+
.replace(/[\n\r\t\s]+/g, ' ')
|
|
19
|
+
.trim()
|
|
20
|
+
)}`;
|
|
21
|
+
|
|
14
22
|
// location of code in file
|
|
15
23
|
let file_loc;
|
|
16
24
|
// cursor pos and width for file_loc overlay positioning
|
|
@@ -131,7 +139,6 @@
|
|
|
131
139
|
const b = document.body;
|
|
132
140
|
if (options.customStyles) {
|
|
133
141
|
b.classList.add('svelte-inspector-enabled');
|
|
134
|
-
b.style.setProperty('--svelte-inspector-cursor', `url(${JSON.stringify(icon)})`);
|
|
135
142
|
}
|
|
136
143
|
listeners(b, enabled);
|
|
137
144
|
}
|
|
@@ -143,12 +150,17 @@
|
|
|
143
150
|
listeners(b, enabled);
|
|
144
151
|
if (options.customStyles) {
|
|
145
152
|
b.classList.remove('svelte-inspector-enabled');
|
|
146
|
-
b.style.removeProperty('--svelte-inspector-cursor');
|
|
147
153
|
active_el?.classList.remove('svelte-inspector-active-target');
|
|
148
154
|
}
|
|
155
|
+
active_el = null;
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
onMount(() => {
|
|
159
|
+
const s = document.createElement('style');
|
|
160
|
+
s.setAttribute('type', 'text/css');
|
|
161
|
+
s.setAttribute('id', 'svelte-inspector-style');
|
|
162
|
+
s.textContent = `:root { --svelte-inspector-icon: url(${icon})};`;
|
|
163
|
+
document.head.append(s);
|
|
152
164
|
if (toggle_combo) {
|
|
153
165
|
document.body.addEventListener('keydown', keydown);
|
|
154
166
|
if (options.holdMode) {
|
|
@@ -158,6 +170,10 @@
|
|
|
158
170
|
return () => {
|
|
159
171
|
// make sure we get rid of everything
|
|
160
172
|
disable();
|
|
173
|
+
const s = document.head.querySelector('#svelte-inspector-style');
|
|
174
|
+
if (s) {
|
|
175
|
+
document.head.removeChild(s);
|
|
176
|
+
}
|
|
161
177
|
if (toggle_combo) {
|
|
162
178
|
document.body.removeEventListener('keydown', keydown);
|
|
163
179
|
if (options.holdMode) {
|
|
@@ -172,7 +188,7 @@
|
|
|
172
188
|
<div
|
|
173
189
|
class="svelte-inspector-toggle"
|
|
174
190
|
class:enabled
|
|
175
|
-
style={`background-image:
|
|
191
|
+
style={`background-image: var(--svelte-inspector-icon);${options.toggleButtonPos
|
|
176
192
|
.split('-')
|
|
177
193
|
.map((p) => `${p}: 8px;`)
|
|
178
194
|
.join('')}`}
|
|
@@ -193,7 +209,7 @@
|
|
|
193
209
|
|
|
194
210
|
<style>
|
|
195
211
|
:global(body.svelte-inspector-enabled *) {
|
|
196
|
-
cursor: var(--svelte-inspector-
|
|
212
|
+
cursor: var(--svelte-inspector-icon), crosshair !important;
|
|
197
213
|
}
|
|
198
214
|
:global(.svelte-inspector-active-target) {
|
|
199
215
|
outline: 2px dashed #ff3e00 !important;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @ts-expect-error virtual import is resolved by vite-plugin-svelte-inspector
|
|
2
1
|
// eslint-disable-next-line node/no-missing-import
|
|
3
|
-
import Inspector from 'virtual:svelte-inspector:Inspector.svelte';
|
|
2
|
+
import Inspector from 'virtual:svelte-inspector-path:Inspector.svelte';
|
|
4
3
|
|
|
5
4
|
function create_inspector_host() {
|
|
6
5
|
const id = 'svelte-inspector-host';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from 'vite';
|
|
1
|
+
import { Plugin, normalizePath } from 'vite';
|
|
3
2
|
import { log } from '../../utils/log';
|
|
4
3
|
import { InspectorOptions } from '../../utils/options';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import fs from 'fs';
|
|
5
7
|
|
|
6
8
|
const defaultInspectorOptions: InspectorOptions = {
|
|
7
9
|
toggleKeyCombo: process.platform === 'win32' ? 'control-shift' : 'meta-shift',
|
|
@@ -11,11 +13,17 @@ const defaultInspectorOptions: InspectorOptions = {
|
|
|
11
13
|
customStyles: true
|
|
12
14
|
};
|
|
13
15
|
|
|
16
|
+
function getInspectorPath() {
|
|
17
|
+
const pluginPath = normalizePath(path.dirname(fileURLToPath(import.meta.url)));
|
|
18
|
+
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, '/vite-plugin-svelte/src/ui/inspector/');
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
export function svelteInspector(): Plugin {
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
const inspectorPath = getInspectorPath();
|
|
23
|
+
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
|
|
17
24
|
let inspectorOptions: InspectorOptions;
|
|
18
|
-
let
|
|
25
|
+
let appendTo: string | undefined;
|
|
26
|
+
let disabled = false;
|
|
19
27
|
|
|
20
28
|
return {
|
|
21
29
|
name: 'vite-plugin-svelte:inspector',
|
|
@@ -31,55 +39,52 @@ export function svelteInspector(): Plugin {
|
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
41
|
if (!vps || !inspectorOptions) {
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
log.debug('inspector disabled, could not find config');
|
|
43
|
+
disabled = true;
|
|
36
44
|
} else {
|
|
37
|
-
root = config.root || process.cwd();
|
|
38
|
-
rootRequire = createRequire(root);
|
|
39
45
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
40
46
|
const out_dir = vps.api.options.kit.outDir || '.svelte-kit';
|
|
41
47
|
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
42
48
|
}
|
|
43
|
-
|
|
49
|
+
appendTo = inspectorOptions.appendTo;
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
|
|
47
53
|
async resolveId(importee: string, importer, options) {
|
|
48
|
-
if (options?.ssr) {
|
|
54
|
+
if (options?.ssr || disabled) {
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
|
-
if (importee
|
|
57
|
+
if (importee.startsWith('virtual:svelte-inspector-options')) {
|
|
52
58
|
return importee;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
'virtual:svelte-inspector:',
|
|
58
|
-
'@sveltejs/vite-plugin-svelte/src/ui/inspector/'
|
|
59
|
-
);
|
|
60
|
-
const path = rootRequire.resolve(file);
|
|
61
|
-
if (path) {
|
|
62
|
-
return path;
|
|
63
|
-
} else {
|
|
64
|
-
log.error.once(`failed to resolve ${file} for ${importee} from ${root}`);
|
|
65
|
-
}
|
|
59
|
+
} else if (importee.startsWith('virtual:svelte-inspector-path:')) {
|
|
60
|
+
const resolved = importee.replace('virtual:svelte-inspector-path:', inspectorPath);
|
|
61
|
+
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
|
|
62
|
+
return resolved;
|
|
66
63
|
}
|
|
67
64
|
},
|
|
68
|
-
|
|
65
|
+
|
|
66
|
+
async load(id, options) {
|
|
67
|
+
if (options?.ssr || disabled) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
69
70
|
if (id === 'virtual:svelte-inspector-options') {
|
|
70
71
|
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
72
|
+
} else if (id.startsWith(inspectorPath)) {
|
|
73
|
+
// read file ourselves to avoid getting shut out by vites fs.allow check
|
|
74
|
+
return await fs.promises.readFile(id, 'utf-8');
|
|
71
75
|
}
|
|
72
76
|
},
|
|
77
|
+
|
|
73
78
|
transform(code: string, id: string, options?: { ssr?: boolean }) {
|
|
74
|
-
if (options?.ssr || !
|
|
79
|
+
if (options?.ssr || disabled || !appendTo) {
|
|
75
80
|
return;
|
|
76
81
|
}
|
|
77
|
-
if (id.endsWith(
|
|
78
|
-
return { code: `${code}\nimport 'virtual:svelte-inspector:load-inspector.
|
|
82
|
+
if (id.endsWith(appendTo)) {
|
|
83
|
+
return { code: `${code}\nimport 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
79
84
|
}
|
|
80
85
|
},
|
|
81
86
|
transformIndexHtml(html) {
|
|
82
|
-
if (
|
|
87
|
+
if (disabled || appendTo) {
|
|
83
88
|
return;
|
|
84
89
|
}
|
|
85
90
|
return {
|
|
@@ -91,7 +96,7 @@ export function svelteInspector(): Plugin {
|
|
|
91
96
|
attrs: {
|
|
92
97
|
type: 'module',
|
|
93
98
|
// /@id/ is needed, otherwise the virtual: is seen as protocol by browser and cors error happens
|
|
94
|
-
src: '/@id/virtual:svelte-inspector:load-inspector.
|
|
99
|
+
src: '/@id/virtual:svelte-inspector-path:load-inspector.js'
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
]
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="25" viewBox="0 0 107 128">
|
|
2
|
-
<title>svelte-inspector-logo</title>
|
|
3
|
-
<path d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157" style="fill:#ff3e00"/><path d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287" style="fill:#fff"/>
|
|
4
|
-
<polygon points="0,0 15,40 40,20" stroke="#ff3e00" fill="#ff3e00"></polygon>
|
|
5
|
-
</svg>
|