@sveltejs/vite-plugin-svelte 6.1.4 → 6.2.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 +1 -1
- package/src/plugins/configure.js +33 -0
- package/src/utils/svelte-version.js +22 -3
package/package.json
CHANGED
package/src/plugins/configure.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '../utils/options.js';
|
|
13
13
|
import { buildIdFilter, buildIdParser } from '../utils/id.js';
|
|
14
14
|
import { createCompileSvelte } from '../utils/compile.js';
|
|
15
|
+
import { gte } from '../utils/svelte-version.js';
|
|
15
16
|
|
|
16
17
|
// @ts-ignore rolldownVersion
|
|
17
18
|
const { version: viteVersion, rolldownVersion } = vite;
|
|
@@ -58,7 +59,39 @@ export function configure(api, inlineOptions) {
|
|
|
58
59
|
preOptions = await preResolveOptions(inlineOptions, config, configEnv);
|
|
59
60
|
// extra vite config
|
|
60
61
|
const extraViteConfig = await buildExtraViteConfig(preOptions, config);
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
rolldownVersion &&
|
|
65
|
+
configEnv.command === 'build' &&
|
|
66
|
+
gte(rolldownVersion, '1.0.0-beta.35') // inlineConst received a critical bugfix in 1.0.0-beta.35
|
|
67
|
+
) {
|
|
68
|
+
extraViteConfig.build ??= {};
|
|
69
|
+
// rename rollupOptions to rolldownOptions
|
|
70
|
+
//@ts-ignore rolldownOptions only exists in rolldown-vite
|
|
71
|
+
extraViteConfig.build.rolldownOptions = extraViteConfig.build.rollupOptions || {};
|
|
72
|
+
delete extraViteConfig.build.rollupOptions;
|
|
73
|
+
// read user config inlineConst value
|
|
74
|
+
const inlineConst =
|
|
75
|
+
//@ts-ignore optimization only exists in rolldown-vite
|
|
76
|
+
config.build?.rolldownOptions?.optimization?.inlineConst ??
|
|
77
|
+
//@ts-ignore optimization only exists in rolldown-vite
|
|
78
|
+
config.build?.rollupOptions?.optimization?.inlineConst;
|
|
79
|
+
|
|
80
|
+
if (inlineConst == null) {
|
|
81
|
+
// set inlineConst build optimization for esm-env
|
|
82
|
+
//@ts-ignore rolldownOptions only exists in rolldown-vite
|
|
83
|
+
extraViteConfig.build.rolldownOptions.optimization ??= {};
|
|
84
|
+
//@ts-ignore rolldownOptions only exists in rolldown-vite
|
|
85
|
+
extraViteConfig.build.rolldownOptions.optimization.inlineConst = true;
|
|
86
|
+
} else if (inlineConst === false) {
|
|
87
|
+
log.warn(
|
|
88
|
+
'Your rolldown config contains `optimization.inlineConst: false`. This can lead to increased bundle size and leaked server code in client build.'
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
61
93
|
log.debug('additional vite config', extraViteConfig, 'config');
|
|
94
|
+
|
|
62
95
|
return extraViteConfig;
|
|
63
96
|
}
|
|
64
97
|
},
|
|
@@ -6,15 +6,34 @@ import { VERSION } from 'svelte/compiler';
|
|
|
6
6
|
export const isSvelteWithAsync = gte(VERSION, '5.36.0');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* split semver string and convert to number, ignores non digits in tag
|
|
10
|
+
* @param {string} semver
|
|
11
|
+
* @return {number[]} [major,minor,patch,tag]
|
|
12
|
+
*/
|
|
13
|
+
function splitToNumbers(semver) {
|
|
14
|
+
const num = semver
|
|
15
|
+
.replace(/[^\d.-]/g, '')
|
|
16
|
+
.split(/[.-]+/, 4)
|
|
17
|
+
.map(Number);
|
|
18
|
+
while (num.length < 3) {
|
|
19
|
+
num.push(0);
|
|
20
|
+
}
|
|
21
|
+
if (num.length < 4) {
|
|
22
|
+
num.push(Infinity);
|
|
23
|
+
}
|
|
24
|
+
return num;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* compare semver versions, tags are compared by their numeric part only
|
|
10
29
|
*
|
|
11
30
|
* @param {string} a semver version
|
|
12
31
|
* @param {string} b semver version
|
|
13
32
|
* @return {boolean} true if a is greater or equal to b
|
|
14
33
|
*/
|
|
15
34
|
export function gte(a, b) {
|
|
16
|
-
const aNum = a
|
|
17
|
-
const bNum = b
|
|
35
|
+
const aNum = splitToNumbers(a);
|
|
36
|
+
const bNum = splitToNumbers(b);
|
|
18
37
|
for (let i = 0; i < aNum.length; i++) {
|
|
19
38
|
if (aNum[i] < bNum[i]) {
|
|
20
39
|
return false;
|