@sveltejs/vite-plugin-svelte 3.0.2 → 3.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 +9 -9
- package/src/index.js +2 -1
- package/src/utils/compile.js +2 -8
- package/src/utils/load-raw.js +9 -7
- package/src/utils/log.js +2 -5
- package/src/utils/options.js +57 -43
- package/src/utils/svelte-version.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@sveltejs/vite-plugin-svelte-inspector": "^2.0.0",
|
|
39
40
|
"debug": "^4.3.4",
|
|
40
41
|
"deepmerge": "^4.3.1",
|
|
41
42
|
"kleur": "^4.1.5",
|
|
42
|
-
"magic-string": "^0.30.
|
|
43
|
-
"svelte-hmr": "^0.
|
|
44
|
-
"vitefu": "^0.2.5"
|
|
45
|
-
"@sveltejs/vite-plugin-svelte-inspector": "^2.0.0"
|
|
43
|
+
"magic-string": "^0.30.9",
|
|
44
|
+
"svelte-hmr": "^0.16.0",
|
|
45
|
+
"vitefu": "^0.2.5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.12",
|
|
53
|
-
"esbuild": "^0.
|
|
54
|
-
"sass": "^1.
|
|
55
|
-
"svelte": "^4.2.
|
|
56
|
-
"vite": "^5.
|
|
53
|
+
"esbuild": "^0.20.2",
|
|
54
|
+
"sass": "^1.74.1",
|
|
55
|
+
"svelte": "^4.2.12",
|
|
56
|
+
"vite": "^5.2.8"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"check:publint": "publint --strict",
|
package/src/index.js
CHANGED
|
@@ -178,7 +178,8 @@ export function svelte(inlineOptions) {
|
|
|
178
178
|
},
|
|
179
179
|
|
|
180
180
|
handleHotUpdate(ctx) {
|
|
181
|
-
|
|
181
|
+
// @ts-expect-error svelte4 does not have hmr option
|
|
182
|
+
if ((!options.hot && !options.compilerOptions.hmr) || !options.emitCss) {
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
184
185
|
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
|
package/src/utils/compile.js
CHANGED
|
@@ -71,13 +71,6 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
71
71
|
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
|
72
72
|
compileOptions.cssHash = () => hash;
|
|
73
73
|
}
|
|
74
|
-
if (ssr && compileOptions.enableSourcemap !== false) {
|
|
75
|
-
if (typeof compileOptions.enableSourcemap === 'object') {
|
|
76
|
-
compileOptions.enableSourcemap.css = false;
|
|
77
|
-
} else {
|
|
78
|
-
compileOptions.enableSourcemap = { js: true, css: false };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
74
|
|
|
82
75
|
let preprocessed;
|
|
83
76
|
let preprocessors = options.preprocess;
|
|
@@ -210,7 +203,8 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
210
203
|
* @returns {Function | undefined}
|
|
211
204
|
*/
|
|
212
205
|
function buildMakeHot(options) {
|
|
213
|
-
const needsMakeHot =
|
|
206
|
+
const needsMakeHot =
|
|
207
|
+
!isSvelte5 && options.hot !== false && options.isServe && !options.isProduction;
|
|
214
208
|
if (needsMakeHot) {
|
|
215
209
|
// @ts-ignore
|
|
216
210
|
const hotApi = options?.hot?.hotApi;
|
package/src/utils/load-raw.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { toRollupError } from './error.js';
|
|
3
3
|
import { log } from './log.js';
|
|
4
|
-
import { isSvelte4 } from './svelte-version.js';
|
|
4
|
+
import { isSvelte4, isSvelte5 } from './svelte-version.js';
|
|
5
5
|
/**
|
|
6
6
|
* utility function to compile ?raw and ?direct requests in load hook
|
|
7
7
|
*
|
|
@@ -27,12 +27,14 @@ export async function loadRaw(svelteRequest, compileSvelte, options) {
|
|
|
27
27
|
compilerOptions: {
|
|
28
28
|
dev: false,
|
|
29
29
|
css: 'external',
|
|
30
|
-
enableSourcemap:
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
enableSourcemap: isSvelte5
|
|
31
|
+
? undefined
|
|
32
|
+
: query.sourcemap
|
|
33
|
+
? {
|
|
34
|
+
js: type === 'script' || type === 'all',
|
|
35
|
+
css: type === 'style' || type === 'all'
|
|
36
|
+
}
|
|
37
|
+
: false,
|
|
36
38
|
...svelteRequest.query.compilerOptions
|
|
37
39
|
},
|
|
38
40
|
hot: false,
|
package/src/utils/log.js
CHANGED
|
@@ -262,10 +262,7 @@ export function isDebugNamespaceEnabled(namespace) {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
export function logSvelte5Warning() {
|
|
265
|
-
const notice = `
|
|
266
|
-
const wip = [
|
|
267
|
-
'svelte-inspector is disabled until dev mode implements node to code mapping',
|
|
268
|
-
'hmr for .svelte files is disabled until hmr api is implemented'
|
|
269
|
-
];
|
|
265
|
+
const notice = `You are using Svelte ${VERSION}. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.`;
|
|
266
|
+
const wip = ['svelte-inspector is disabled until dev mode implements node to code mapping'];
|
|
270
267
|
log.warn(`${notice}\nwork in progress:\n - ${wip.join('\n - ')}\n`);
|
|
271
268
|
}
|
package/src/utils/options.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import { isCommonDepWithoutSvelteField } from './dependencies.js';
|
|
27
27
|
import { VitePluginSvelteStats } from './vite-plugin-svelte-stats.js';
|
|
28
28
|
import { VitePluginSvelteCache } from './vite-plugin-svelte-cache.js';
|
|
29
|
-
import { isSvelte5 } from './svelte-version.js';
|
|
29
|
+
import { isSvelte5, isSvelte5WithHMRSupport } from './svelte-version.js';
|
|
30
30
|
|
|
31
31
|
const allowedPluginOptions = new Set([
|
|
32
32
|
'include',
|
|
@@ -194,17 +194,24 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
|
|
|
194
194
|
const css = preResolveOptions.emitCss ? 'external' : 'injected';
|
|
195
195
|
/** @type {Partial<import('../public.d.ts').Options>} */
|
|
196
196
|
const defaultOptions = {
|
|
197
|
-
hot: viteConfig.isProduction
|
|
198
|
-
? false
|
|
199
|
-
: {
|
|
200
|
-
injectCss: css === 'injected',
|
|
201
|
-
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
|
|
202
|
-
},
|
|
203
197
|
compilerOptions: {
|
|
204
198
|
css,
|
|
205
199
|
dev: !viteConfig.isProduction
|
|
206
200
|
}
|
|
207
201
|
};
|
|
202
|
+
if (isSvelte5) {
|
|
203
|
+
if (isSvelte5WithHMRSupport) {
|
|
204
|
+
// @ts-expect-error svelte4 does not have hmr option
|
|
205
|
+
defaultOptions.compilerOptions.hmr = !viteConfig.isProduction;
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
defaultOptions.hot = viteConfig.isProduction
|
|
209
|
+
? false
|
|
210
|
+
: {
|
|
211
|
+
injectCss: css === 'injected',
|
|
212
|
+
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
|
|
213
|
+
};
|
|
214
|
+
}
|
|
208
215
|
/** @type {Partial<import('../types/options.d.ts').ResolvedOptions>} */
|
|
209
216
|
const extraOptions = {
|
|
210
217
|
root: viteConfig.root,
|
|
@@ -231,45 +238,52 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
|
|
|
231
238
|
*/
|
|
232
239
|
function enforceOptionsForHmr(options) {
|
|
233
240
|
if (isSvelte5) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
options.compilerOptions.
|
|
241
|
+
if (options.hot && isSvelte5WithHMRSupport) {
|
|
242
|
+
log.warn(
|
|
243
|
+
'svelte 5 has hmr integrated in core. Please remove the hot option and use compilerOptions.hmr instead'
|
|
244
|
+
);
|
|
245
|
+
delete options.hot;
|
|
246
|
+
// @ts-expect-error hmr option doesn't exist in svelte4
|
|
247
|
+
options.compilerOptions.hmr = true;
|
|
241
248
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const css = options.compilerOptions.css;
|
|
248
|
-
if (css === true || css === 'injected') {
|
|
249
|
-
const forcedCss = 'external';
|
|
250
|
-
log.warn(
|
|
251
|
-
`hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
|
|
252
|
-
);
|
|
253
|
-
options.compilerOptions.css = forcedCss;
|
|
249
|
+
} else {
|
|
250
|
+
if (options.hot) {
|
|
251
|
+
if (!options.compilerOptions.dev) {
|
|
252
|
+
log.warn('hmr is enabled but compilerOptions.dev is false, forcing it to true');
|
|
253
|
+
options.compilerOptions.dev = true;
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
255
|
+
if (options.emitCss) {
|
|
256
|
+
if (options.hot !== true && options.hot.injectCss) {
|
|
257
|
+
log.warn('hmr and emitCss are enabled but hot.injectCss is true, forcing it to false');
|
|
258
|
+
options.hot.injectCss = false;
|
|
259
|
+
}
|
|
260
|
+
const css = options.compilerOptions.css;
|
|
261
|
+
if (css === true || css === 'injected') {
|
|
262
|
+
const forcedCss = 'external';
|
|
263
|
+
log.warn(
|
|
264
|
+
`hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
|
|
265
|
+
);
|
|
266
|
+
options.compilerOptions.css = forcedCss;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
if (options.hot === true || !options.hot.injectCss) {
|
|
270
|
+
log.warn(
|
|
271
|
+
'hmr with emitCss disabled requires option hot.injectCss to be enabled, forcing it to true'
|
|
272
|
+
);
|
|
273
|
+
if (options.hot === true) {
|
|
274
|
+
options.hot = { injectCss: true };
|
|
275
|
+
} else {
|
|
276
|
+
options.hot.injectCss = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const css = options.compilerOptions.css;
|
|
280
|
+
if (!(css === true || css === 'injected')) {
|
|
281
|
+
const forcedCss = 'injected';
|
|
282
|
+
log.warn(
|
|
283
|
+
`hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
|
|
284
|
+
);
|
|
285
|
+
options.compilerOptions.css = forcedCss;
|
|
264
286
|
}
|
|
265
|
-
}
|
|
266
|
-
const css = options.compilerOptions.css;
|
|
267
|
-
if (!(css === true || css === 'injected')) {
|
|
268
|
-
const forcedCss = 'injected';
|
|
269
|
-
log.warn(
|
|
270
|
-
`hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
|
|
271
|
-
);
|
|
272
|
-
options.compilerOptions.css = forcedCss;
|
|
273
287
|
}
|
|
274
288
|
}
|
|
275
289
|
}
|
|
@@ -9,3 +9,9 @@ export const isSvelte4 = VERSION.startsWith('4.');
|
|
|
9
9
|
* @type {boolean}
|
|
10
10
|
*/
|
|
11
11
|
export const isSvelte5 = VERSION.startsWith('5.');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export const isSvelte5WithHMRSupport =
|
|
17
|
+
VERSION.startsWith('5.0.0-next.') && Number(VERSION.slice(11)) > 96;
|