@sveltejs/vite-plugin-svelte 5.0.2 → 5.1.0
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/package.json +7 -8
- package/src/index.js +9 -2
- package/src/types/compile.d.ts +5 -0
- package/src/utils/compile.js +1 -1
- package/src/utils/constants.js +8 -3
- package/src/utils/error.js +5 -3
- package/src/utils/options.js +4 -2
- package/types/index.d.ts.map +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@sveltejs/vite-plugin-svelte-inspector": "^4.0.1",
|
|
40
|
-
"debug": "^4.4.
|
|
40
|
+
"debug": "^4.4.1",
|
|
41
41
|
"deepmerge": "^4.3.1",
|
|
42
42
|
"kleur": "^4.1.5",
|
|
43
|
-
"magic-string": "^0.30.
|
|
44
|
-
"vitefu": "^1.0.
|
|
43
|
+
"magic-string": "^0.30.17",
|
|
44
|
+
"vitefu": "^1.0.6"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"svelte": "^5.0.0",
|
|
@@ -49,10 +49,9 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/debug": "^4.1.12",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"vite": "^6.0.3"
|
|
52
|
+
"sass": "^1.89.0",
|
|
53
|
+
"svelte": "^5.33.3",
|
|
54
|
+
"vite": "^6.3.5"
|
|
56
55
|
},
|
|
57
56
|
"scripts": {
|
|
58
57
|
"check:publint": "publint --strict",
|
package/src/index.js
CHANGED
|
@@ -118,8 +118,15 @@ export function svelte(inlineOptions) {
|
|
|
118
118
|
};
|
|
119
119
|
} else {
|
|
120
120
|
if (query.svelte && query.type === 'style') {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
121
|
+
const cachedCss = cache.getCSS(svelteRequest);
|
|
122
|
+
if (cachedCss) {
|
|
123
|
+
const { hasGlobal, ...css } = cachedCss;
|
|
124
|
+
if (hasGlobal === false) {
|
|
125
|
+
// hasGlobal was added in svelte 5.26.0, so make sure it is boolean false
|
|
126
|
+
css.meta ??= {};
|
|
127
|
+
css.meta.vite ??= {};
|
|
128
|
+
css.meta.vite.cssScopeTo = [svelteRequest.filename, 'default'];
|
|
129
|
+
}
|
|
123
130
|
return css;
|
|
124
131
|
}
|
|
125
132
|
}
|
package/src/types/compile.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Processed, CompileResult } from 'svelte/compiler';
|
|
2
2
|
import type { SvelteRequest } from './id.d.ts';
|
|
3
3
|
import type { ResolvedOptions } from './options.d.ts';
|
|
4
|
+
import type { CustomPluginOptionsVite } from 'vite';
|
|
4
5
|
|
|
5
6
|
export type CompileSvelte = (
|
|
6
7
|
svelteRequest: SvelteRequest,
|
|
@@ -12,6 +13,10 @@ export interface Code {
|
|
|
12
13
|
code: string;
|
|
13
14
|
map?: any;
|
|
14
15
|
dependencies?: any[];
|
|
16
|
+
hasGlobal?: boolean;
|
|
17
|
+
meta?: {
|
|
18
|
+
vite?: CustomPluginOptionsVite;
|
|
19
|
+
};
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface CompileData {
|
package/src/utils/compile.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as svelte from 'svelte/compiler';
|
|
2
|
-
|
|
3
2
|
import { safeBase64Hash } from './hash.js';
|
|
4
3
|
import { log } from './log.js';
|
|
5
4
|
|
|
@@ -133,6 +132,7 @@ export function createCompileSvelte() {
|
|
|
133
132
|
let compiled;
|
|
134
133
|
try {
|
|
135
134
|
compiled = svelte.compile(finalCode, { ...finalCompileOptions, filename });
|
|
135
|
+
|
|
136
136
|
// patch output with partial accept until svelte does it
|
|
137
137
|
// TODO remove later
|
|
138
138
|
if (
|
package/src/utils/constants.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const sveltePkg = createRequire(import.meta.url)('svelte/package.json');
|
|
4
|
+
|
|
5
|
+
// list of svelte runtime dependencies to optimize together with svelte itself
|
|
6
|
+
export const SVELTE_RUNTIME_DEPENDENCIES = [
|
|
7
|
+
'clsx' // avoids dev server restart after page load with npm + vite6 (see #1067)
|
|
8
|
+
].filter((dep) => !!sveltePkg.dependencies?.[dep]);
|
|
9
|
+
|
|
10
|
+
export const SVELTE_IMPORTS = Object.entries(sveltePkg.exports)
|
|
6
11
|
.map(([name, config]) => {
|
|
7
12
|
// ignore type only
|
|
8
13
|
if (typeof config === 'object' && Object.keys(config).length === 1 && config.types) {
|
package/src/utils/error.js
CHANGED
|
@@ -31,11 +31,13 @@ export function toRollupError(error, options) {
|
|
|
31
31
|
* convert an error thrown by svelte.compile to an esbuild PartialMessage
|
|
32
32
|
* @param {import('svelte/compiler').Warning & Error & {frame?: string}} error a svelte compiler error, which is a mix of Warning and an error
|
|
33
33
|
* @param {import('../types/options.d.ts').ResolvedOptions} options
|
|
34
|
-
* @returns {
|
|
34
|
+
* @returns {any} the converted error as esbuild PartialMessage
|
|
35
|
+
*
|
|
36
|
+
* note: typed any to avoid esbuild devDependency for a single internal type import
|
|
35
37
|
*/
|
|
36
38
|
export function toESBuildError(error, options) {
|
|
37
39
|
const { filename, frame, start, stack } = error;
|
|
38
|
-
/** @type
|
|
40
|
+
/** @type any */
|
|
39
41
|
const partialMessage = {
|
|
40
42
|
text: buildExtendedLogMessage(error)
|
|
41
43
|
};
|
|
@@ -108,7 +110,7 @@ function formatFrameForVite(frame) {
|
|
|
108
110
|
* @returns {boolean}
|
|
109
111
|
*/
|
|
110
112
|
function couldBeFixedByCssPreprocessor(code) {
|
|
111
|
-
return code === 'expected_token' || code === 'unexpected_eof' || code
|
|
113
|
+
return code === 'expected_token' || code === 'unexpected_eof' || code?.startsWith('css_');
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
/**
|
package/src/utils/options.js
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
DEFAULT_SVELTE_EXT,
|
|
13
13
|
FAQ_LINK_MISSING_EXPORTS_CONDITION,
|
|
14
14
|
SVELTE_EXPORT_CONDITIONS,
|
|
15
|
-
SVELTE_IMPORTS
|
|
15
|
+
SVELTE_IMPORTS,
|
|
16
|
+
SVELTE_RUNTIME_DEPENDENCIES
|
|
16
17
|
} from './constants.js';
|
|
17
18
|
|
|
18
19
|
import path from 'node:path';
|
|
@@ -550,8 +551,9 @@ function buildExtraConfigForSvelte(config) {
|
|
|
550
551
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter(
|
|
551
552
|
(si) => !(si.endsWith('/server') || si.includes('/server/'))
|
|
552
553
|
);
|
|
554
|
+
svelteImportsToInclude.push(...SVELTE_RUNTIME_DEPENDENCIES.map((dep) => `svelte > ${dep}`));
|
|
553
555
|
log.debug(
|
|
554
|
-
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(', ')} `,
|
|
556
|
+
`adding bare svelte packages and runtime dependencies to optimizeDeps.include: ${svelteImportsToInclude.join(', ')} `,
|
|
555
557
|
undefined,
|
|
556
558
|
'config'
|
|
557
559
|
);
|
package/types/index.d.ts.map
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
"file": "index.d.ts",
|
|
4
4
|
"names": [
|
|
5
5
|
"Options",
|
|
6
|
+
"PluginOptionsInline",
|
|
6
7
|
"PluginOptions",
|
|
7
8
|
"SvelteConfig",
|
|
9
|
+
"ExperimentalOptions",
|
|
10
|
+
"CompileModuleOptions",
|
|
11
|
+
"Arrayable",
|
|
8
12
|
"VitePreprocessOptions",
|
|
9
13
|
"svelte",
|
|
10
14
|
"vitePreprocess",
|
|
@@ -22,5 +26,6 @@
|
|
|
22
26
|
null,
|
|
23
27
|
null
|
|
24
28
|
],
|
|
25
|
-
"mappings": ";;;;aAIYA,OAAOA
|
|
29
|
+
"mappings": ";;;;aAIYA,OAAOA;;WAETC,mBAAmBA;;;;;;;;;;;kBAWZC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAiDnBC,mBAAmBA;;;;;;;;;;;;;;;;WAgBnBC,oBAAoBA;;;;;;;;;;;;;;;MAezBC,SAASA;;kBAEGC,qBAAqBA;;;;;;;;;;;;;iBCxKtBC,MAAMA;iBCXNC,cAAcA;iBCgBRC,gBAAgBA",
|
|
30
|
+
"ignoreList": []
|
|
26
31
|
}
|