@sveltejs/vite-plugin-svelte 1.0.0-next.45 → 1.0.0-next.48
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 +25 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/index.ts +2 -0
- package/src/utils/dependencies.ts +5 -1
- package/src/utils/load-svelte-config.ts +12 -8
- package/src/utils/options.ts +27 -3
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.48",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"deepmerge": "^4.2.2",
|
|
47
47
|
"kleur": "^4.1.4",
|
|
48
48
|
"magic-string": "^0.26.2",
|
|
49
|
-
"svelte-hmr": "^0.14.
|
|
49
|
+
"svelte-hmr": "^0.14.12"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"diff-match-patch": "^1.0.5",
|
|
@@ -59,18 +59,19 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
+
"@sveltejs/kit": "^1.0.0-next.350",
|
|
62
63
|
"@types/debug": "^4.1.7",
|
|
63
64
|
"@types/diff-match-patch": "^1.0.32",
|
|
64
65
|
"diff-match-patch": "^1.0.5",
|
|
65
|
-
"esbuild": "^0.14.
|
|
66
|
-
"rollup": "^2.
|
|
66
|
+
"esbuild": "^0.14.42",
|
|
67
|
+
"rollup": "^2.75.5",
|
|
67
68
|
"svelte": "^3.48.0",
|
|
68
|
-
"tsup": "^
|
|
69
|
-
"vite": "^2.9.
|
|
69
|
+
"tsup": "^6.1.0",
|
|
70
|
+
"vite": "^2.9.10"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"dev": "pnpm build:ci --sourcemap --watch src",
|
|
73
|
-
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting --
|
|
74
|
+
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting --shims",
|
|
74
75
|
"build": "pnpm build:ci --dts --sourcemap"
|
|
75
76
|
}
|
|
76
77
|
}
|
package/src/index.ts
CHANGED
|
@@ -127,6 +127,7 @@ function isSvelteLib(pkg: Pkg) {
|
|
|
127
127
|
|
|
128
128
|
const COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
129
129
|
'@lukeed/uuid',
|
|
130
|
+
'@playwright/test',
|
|
130
131
|
'@sveltejs/vite-plugin-svelte',
|
|
131
132
|
'@sveltejs/kit',
|
|
132
133
|
'autoprefixer',
|
|
@@ -136,6 +137,7 @@ const COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
136
137
|
'eslint',
|
|
137
138
|
'jest',
|
|
138
139
|
'mdsvex',
|
|
140
|
+
'playwright',
|
|
139
141
|
'postcss',
|
|
140
142
|
'prettier',
|
|
141
143
|
'svelte',
|
|
@@ -144,7 +146,9 @@ const COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
144
146
|
'svelte-preprocess',
|
|
145
147
|
'tslib',
|
|
146
148
|
'typescript',
|
|
147
|
-
'vite'
|
|
149
|
+
'vite',
|
|
150
|
+
'vitest',
|
|
151
|
+
'__vite-browser-external' // see https://github.com/sveltejs/vite-plugin-svelte/issues/362
|
|
148
152
|
];
|
|
149
153
|
const COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
|
|
150
154
|
'@fontsource/',
|
|
@@ -22,14 +22,15 @@ export const knownSvelteConfigNames = [
|
|
|
22
22
|
// also use timestamp query to avoid caching on reload
|
|
23
23
|
const dynamicImportDefault = new Function(
|
|
24
24
|
'path',
|
|
25
|
-
'
|
|
25
|
+
'timestamp',
|
|
26
|
+
'return import(path + "?t=" + timestamp).then(m => m.default)'
|
|
26
27
|
);
|
|
27
28
|
|
|
28
29
|
export async function loadSvelteConfig(
|
|
29
|
-
viteConfig
|
|
30
|
-
inlineOptions
|
|
30
|
+
viteConfig?: UserConfig,
|
|
31
|
+
inlineOptions?: Partial<Options>
|
|
31
32
|
): Promise<Partial<Options> | undefined> {
|
|
32
|
-
if (inlineOptions
|
|
33
|
+
if (inlineOptions?.configFile === false) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
36
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
@@ -38,7 +39,10 @@ export async function loadSvelteConfig(
|
|
|
38
39
|
// try to use dynamic import for svelte.config.js first
|
|
39
40
|
if (configFile.endsWith('.js') || configFile.endsWith('.mjs')) {
|
|
40
41
|
try {
|
|
41
|
-
const result = await dynamicImportDefault(
|
|
42
|
+
const result = await dynamicImportDefault(
|
|
43
|
+
pathToFileURL(configFile).href,
|
|
44
|
+
fs.statSync(configFile).mtimeMs
|
|
45
|
+
);
|
|
42
46
|
if (result != null) {
|
|
43
47
|
return {
|
|
44
48
|
...result,
|
|
@@ -83,9 +87,9 @@ export async function loadSvelteConfig(
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
function findConfigToLoad(viteConfig
|
|
87
|
-
const root = viteConfig
|
|
88
|
-
if (inlineOptions
|
|
90
|
+
function findConfigToLoad(viteConfig?: UserConfig, inlineOptions?: Partial<Options>) {
|
|
91
|
+
const root = viteConfig?.root || process.cwd();
|
|
92
|
+
if (inlineOptions?.configFile) {
|
|
89
93
|
const abolutePath = path.isAbsolute(inlineOptions.configFile)
|
|
90
94
|
? inlineOptions.configFile
|
|
91
95
|
: path.resolve(root, inlineOptions.configFile);
|
package/src/utils/options.ts
CHANGED
|
@@ -11,14 +11,16 @@ import { log } from './log';
|
|
|
11
11
|
import { loadSvelteConfig } from './load-svelte-config';
|
|
12
12
|
import { SVELTE_HMR_IMPORTS, SVELTE_IMPORTS, SVELTE_RESOLVE_MAIN_FIELDS } from './constants';
|
|
13
13
|
// eslint-disable-next-line node/no-missing-import
|
|
14
|
-
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
15
|
-
import {
|
|
14
|
+
import type { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
15
|
+
import type {
|
|
16
16
|
MarkupPreprocessor,
|
|
17
17
|
Preprocessor,
|
|
18
18
|
PreprocessorGroup,
|
|
19
19
|
Processed
|
|
20
20
|
// eslint-disable-next-line node/no-missing-import
|
|
21
21
|
} from 'svelte/types/compiler/preprocess';
|
|
22
|
+
// eslint-disable-next-line node/no-missing-import
|
|
23
|
+
import type { KitConfig } from '@sveltejs/kit';
|
|
22
24
|
import path from 'path';
|
|
23
25
|
import { findRootSvelteDependencies, needsOptimization, SvelteDependency } from './dependencies';
|
|
24
26
|
import { createRequire } from 'module';
|
|
@@ -76,7 +78,6 @@ export async function preResolveOptions(
|
|
|
76
78
|
inlineOptions,
|
|
77
79
|
extraOptions
|
|
78
80
|
);
|
|
79
|
-
|
|
80
81
|
// configFile of svelteConfig contains the absolute path it was loaded from,
|
|
81
82
|
// prefer it over the possibly relative inline path
|
|
82
83
|
if (svelteConfig?.configFile) {
|
|
@@ -116,6 +117,7 @@ export function resolveOptions(
|
|
|
116
117
|
const merged: ResolvedOptions = mergeConfigs(defaultOptions, preResolveOptions, extraOptions);
|
|
117
118
|
|
|
118
119
|
removeIgnoredOptions(merged);
|
|
120
|
+
addSvelteKitOptions(merged);
|
|
119
121
|
addExtraPreprocessors(merged, viteConfig);
|
|
120
122
|
enforceOptionsForHmr(merged);
|
|
121
123
|
enforceOptionsForProduction(merged);
|
|
@@ -195,6 +197,23 @@ function removeIgnoredOptions(options: ResolvedOptions) {
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
|
|
200
|
+
// some SvelteKit options need compilerOptions to work, so set them here.
|
|
201
|
+
function addSvelteKitOptions(options: ResolvedOptions) {
|
|
202
|
+
if (options?.kit != null) {
|
|
203
|
+
const hydratable = options.kit.browser?.hydrate !== false;
|
|
204
|
+
if (
|
|
205
|
+
options.compilerOptions.hydratable != null &&
|
|
206
|
+
options.compilerOptions.hydratable !== hydratable
|
|
207
|
+
) {
|
|
208
|
+
log.warn(
|
|
209
|
+
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${options.kit.browser?.hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
|
|
213
|
+
options.compilerOptions.hydratable = hydratable;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
198
217
|
// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
|
|
199
218
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/113
|
|
200
219
|
// https://github.com/vitejs/vite/blob/43c957de8a99bb326afd732c962f42127b0a4d1e/packages/vite/src/node/config.ts#L293
|
|
@@ -476,6 +495,11 @@ export interface Options {
|
|
|
476
495
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
477
496
|
*/
|
|
478
497
|
experimental?: ExperimentalOptions;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Options for SvelteKit
|
|
501
|
+
*/
|
|
502
|
+
kit?: KitConfig;
|
|
479
503
|
}
|
|
480
504
|
|
|
481
505
|
/**
|