@sveltejs/vite-plugin-svelte 4.0.2 → 5.0.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 +6 -6
- package/src/index.js +18 -2
- package/src/types/id.d.ts +1 -0
- package/src/utils/constants.js +0 -4
- package/src/utils/options.js +49 -16
- package/types/index.d.ts +3 -3
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"debug": "^4.3.7",
|
|
41
41
|
"deepmerge": "^4.3.1",
|
|
42
42
|
"kleur": "^4.1.5",
|
|
43
|
-
"magic-string": "^0.30.
|
|
43
|
+
"magic-string": "^0.30.13",
|
|
44
44
|
"vitefu": "^1.0.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"svelte": "^5.0.0
|
|
48
|
-
"vite": "^
|
|
47
|
+
"svelte": "^5.0.0",
|
|
48
|
+
"vite": "^6.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/debug": "^4.1.12",
|
|
52
52
|
"esbuild": "^0.24.0",
|
|
53
53
|
"sass": "^1.81.0",
|
|
54
|
-
"svelte": "^5.2.
|
|
55
|
-
"vite": "^
|
|
54
|
+
"svelte": "^5.2.7",
|
|
55
|
+
"vite": "^6.0.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"check:publint": "publint --strict",
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,9 @@ import {
|
|
|
10
10
|
validateInlineOptions,
|
|
11
11
|
resolveOptions,
|
|
12
12
|
patchResolvedViteConfig,
|
|
13
|
-
preResolveOptions
|
|
13
|
+
preResolveOptions,
|
|
14
|
+
ensureConfigEnvironmentMainFields,
|
|
15
|
+
ensureConfigEnvironmentConditions
|
|
14
16
|
} from './utils/options.js';
|
|
15
17
|
import { ensureWatchedFile, setupWatchers } from './utils/watch.js';
|
|
16
18
|
import { toRollupError } from './utils/error.js';
|
|
@@ -64,6 +66,16 @@ export function svelte(inlineOptions) {
|
|
|
64
66
|
return extraViteConfig;
|
|
65
67
|
},
|
|
66
68
|
|
|
69
|
+
configEnvironment(name, config, opts) {
|
|
70
|
+
ensureConfigEnvironmentMainFields(name, config, opts);
|
|
71
|
+
// @ts-expect-error the function above should make `resolve.mainFields` non-nullable
|
|
72
|
+
config.resolve.mainFields.unshift('svelte');
|
|
73
|
+
|
|
74
|
+
ensureConfigEnvironmentConditions(name, config, opts);
|
|
75
|
+
// @ts-expect-error the function above should make `resolve.conditions` non-nullable
|
|
76
|
+
config.resolve.conditions.push('svelte');
|
|
77
|
+
},
|
|
78
|
+
|
|
67
79
|
async configResolved(config) {
|
|
68
80
|
options = resolveOptions(options, config, cache);
|
|
69
81
|
patchResolvedViteConfig(config, options);
|
|
@@ -124,7 +136,11 @@ export function svelte(inlineOptions) {
|
|
|
124
136
|
const ssr = !!opts?.ssr;
|
|
125
137
|
const svelteRequest = requestParser(importee, ssr);
|
|
126
138
|
if (svelteRequest?.query.svelte) {
|
|
127
|
-
if (
|
|
139
|
+
if (
|
|
140
|
+
svelteRequest.query.type === 'style' &&
|
|
141
|
+
!svelteRequest.raw &&
|
|
142
|
+
!svelteRequest.query.inline
|
|
143
|
+
) {
|
|
128
144
|
// return cssId with root prefix so postcss pipeline of vite finds the directory correctly
|
|
129
145
|
// see https://github.com/sveltejs/vite-plugin-svelte/issues/14
|
|
130
146
|
log.debug(
|
package/src/types/id.d.ts
CHANGED
package/src/utils/constants.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
|
|
3
|
-
export const VITE_RESOLVE_MAIN_FIELDS = ['browser', 'module', 'jsnext:main', 'jsnext'];
|
|
4
|
-
|
|
5
|
-
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];
|
|
6
|
-
|
|
7
3
|
export const SVELTE_IMPORTS = Object.entries(
|
|
8
4
|
createRequire(import.meta.url)('svelte/package.json').exports
|
|
9
5
|
)
|
package/src/utils/options.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defaultClientMainFields,
|
|
4
|
+
defaultServerMainFields,
|
|
5
|
+
defaultClientConditions,
|
|
6
|
+
defaultServerConditions,
|
|
7
|
+
normalizePath
|
|
8
|
+
} from 'vite';
|
|
3
9
|
import { isDebugNamespaceEnabled, log } from './log.js';
|
|
4
10
|
import { loadSvelteConfig } from './load-svelte-config.js';
|
|
5
11
|
import {
|
|
6
12
|
DEFAULT_SVELTE_EXT,
|
|
7
13
|
FAQ_LINK_MISSING_EXPORTS_CONDITION,
|
|
8
14
|
SVELTE_EXPORT_CONDITIONS,
|
|
9
|
-
SVELTE_IMPORTS
|
|
10
|
-
SVELTE_RESOLVE_MAIN_FIELDS,
|
|
11
|
-
VITE_RESOLVE_MAIN_FIELDS
|
|
15
|
+
SVELTE_IMPORTS
|
|
12
16
|
} from './constants.js';
|
|
13
17
|
|
|
14
18
|
import path from 'node:path';
|
|
@@ -333,21 +337,10 @@ function resolveViteRoot(viteConfig) {
|
|
|
333
337
|
* @returns {Promise<Partial<import('vite').UserConfig>>}
|
|
334
338
|
*/
|
|
335
339
|
export async function buildExtraViteConfig(options, config) {
|
|
336
|
-
// make sure we only readd vite default mainFields when no other plugin has changed the config already
|
|
337
|
-
// see https://github.com/sveltejs/vite-plugin-svelte/issues/581
|
|
338
|
-
if (!config.resolve) {
|
|
339
|
-
config.resolve = {};
|
|
340
|
-
}
|
|
341
|
-
config.resolve.mainFields = [
|
|
342
|
-
...SVELTE_RESOLVE_MAIN_FIELDS,
|
|
343
|
-
...(config.resolve.mainFields ?? VITE_RESOLVE_MAIN_FIELDS)
|
|
344
|
-
];
|
|
345
|
-
|
|
346
340
|
/** @type {Partial<import('vite').UserConfig>} */
|
|
347
341
|
const extraViteConfig = {
|
|
348
342
|
resolve: {
|
|
349
|
-
dedupe: [...SVELTE_IMPORTS]
|
|
350
|
-
conditions: [...SVELTE_EXPORT_CONDITIONS]
|
|
343
|
+
dedupe: [...SVELTE_IMPORTS]
|
|
351
344
|
}
|
|
352
345
|
// this option is still awaiting a PR in vite to be supported
|
|
353
346
|
// see https://github.com/sveltejs/vite-plugin-svelte/issues/60
|
|
@@ -579,6 +572,11 @@ function buildExtraConfigForSvelte(config) {
|
|
|
579
572
|
if (!isDepExternaled('svelte', config.ssr?.external ?? [])) {
|
|
580
573
|
noExternal.push('svelte', /^svelte\//);
|
|
581
574
|
}
|
|
575
|
+
// esm-env needs to be bundled by default for the development/production condition
|
|
576
|
+
// be properly used by svelte
|
|
577
|
+
if (!isDepExternaled('esm-env', config.ssr?.external ?? [])) {
|
|
578
|
+
noExternal.push('esm-env');
|
|
579
|
+
}
|
|
582
580
|
return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
|
|
583
581
|
}
|
|
584
582
|
|
|
@@ -610,6 +608,41 @@ export function patchResolvedViteConfig(viteConfig, options) {
|
|
|
610
608
|
}
|
|
611
609
|
}
|
|
612
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Mutates `config` to ensure `resolve.mainFields` is set. If unset, it emulates Vite's default fallback.
|
|
613
|
+
* @param {string} name
|
|
614
|
+
* @param {import('vite').EnvironmentOptions} config
|
|
615
|
+
* @param {{ isSsrTargetWebworker?: boolean }} opts
|
|
616
|
+
*/
|
|
617
|
+
export function ensureConfigEnvironmentMainFields(name, config, opts) {
|
|
618
|
+
config.resolve ??= {};
|
|
619
|
+
if (config.resolve.mainFields == null) {
|
|
620
|
+
if (config.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
|
|
621
|
+
config.resolve.mainFields = [...defaultClientMainFields];
|
|
622
|
+
} else {
|
|
623
|
+
config.resolve.mainFields = [...defaultServerMainFields];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Mutates `config` to ensure `resolve.conditions` is set. If unset, it emulates Vite's default fallback.
|
|
631
|
+
* @param {string} name
|
|
632
|
+
* @param {import('vite').EnvironmentOptions} config
|
|
633
|
+
* @param {{ isSsrTargetWebworker?: boolean }} opts
|
|
634
|
+
*/
|
|
635
|
+
export function ensureConfigEnvironmentConditions(name, config, opts) {
|
|
636
|
+
config.resolve ??= {};
|
|
637
|
+
if (config.resolve.conditions == null) {
|
|
638
|
+
if (config.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
|
|
639
|
+
config.resolve.conditions = [...defaultClientConditions];
|
|
640
|
+
} else {
|
|
641
|
+
config.resolve.conditions = [...defaultServerConditions];
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
613
646
|
/**
|
|
614
647
|
* @template T
|
|
615
648
|
* @param {T | T[]} value
|
package/types/index.d.ts
CHANGED
|
@@ -206,9 +206,9 @@ declare module '@sveltejs/vite-plugin-svelte' {
|
|
|
206
206
|
*/
|
|
207
207
|
style?: boolean | InlineConfig | ResolvedConfig;
|
|
208
208
|
}
|
|
209
|
-
export function svelte(inlineOptions?: Partial<Options>
|
|
210
|
-
export function vitePreprocess(opts?: VitePreprocessOptions
|
|
211
|
-
export function loadSvelteConfig(viteConfig?: import("vite").UserConfig
|
|
209
|
+
export function svelte(inlineOptions?: Partial<Options>): import("vite").Plugin[];
|
|
210
|
+
export function vitePreprocess(opts?: VitePreprocessOptions): import("svelte/compiler").PreprocessorGroup;
|
|
211
|
+
export function loadSvelteConfig(viteConfig?: import("vite").UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<SvelteConfig> | undefined>;
|
|
212
212
|
|
|
213
213
|
export {};
|
|
214
214
|
}
|
package/types/index.d.ts.map
CHANGED
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
null,
|
|
23
23
|
null
|
|
24
24
|
],
|
|
25
|
-
"mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkFZC,qBAAqBA;;;;;;;;;;;;;
|
|
25
|
+
"mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkFZC,qBAAqBA;;;;;;;;;;;;;iBCxKtBC,MAAMA;iBCXNC,cAAcA;iBCgBRC,gBAAgBA"
|
|
26
26
|
}
|