@sveltejs/vite-plugin-svelte 1.0.9 → 1.1.1
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 +88 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +84 -102
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -1
- package/src/utils/id.ts +1 -1
- package/src/utils/options.ts +20 -9
- package/src/utils/preprocess.ts +33 -26
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,12 @@ interface PluginOptions {
|
|
|
77
77
|
* @default false
|
|
78
78
|
*/
|
|
79
79
|
disableDependencyReinclusion?: boolean | string[];
|
|
80
|
+
/**
|
|
81
|
+
* Force Vite to pre-bundle Svelte libraries
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
prebundleSvelteLibraries?: boolean;
|
|
80
86
|
/**
|
|
81
87
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
82
88
|
*/
|
|
@@ -124,12 +130,6 @@ interface ExperimentalOptions {
|
|
|
124
130
|
* @default false
|
|
125
131
|
*/
|
|
126
132
|
useVitePreprocess?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Force Vite to pre-bundle Svelte libraries
|
|
129
|
-
*
|
|
130
|
-
* @default false
|
|
131
|
-
*/
|
|
132
|
-
prebundleSvelteLibraries?: boolean;
|
|
133
133
|
/**
|
|
134
134
|
* If a preprocessor does not provide a sourcemap, a best-effort fallback sourcemap will be provided.
|
|
135
135
|
* This option requires `diff-match-patch` to be installed as a peer dependency.
|
package/dist/index.js
CHANGED
|
@@ -98,12 +98,11 @@ var log = {
|
|
|
98
98
|
setLevel
|
|
99
99
|
};
|
|
100
100
|
function logCompilerWarnings(svelteRequest, warnings, options) {
|
|
101
|
-
var _a, _b, _c;
|
|
102
101
|
const { emitCss, onwarn, isBuild } = options;
|
|
103
|
-
const sendViaWS = !isBuild &&
|
|
102
|
+
const sendViaWS = !isBuild && options.experimental?.sendWarningsToBrowser;
|
|
104
103
|
let warn = isBuild ? warnBuild : warnDev;
|
|
105
104
|
const handledByDefaultWarn = [];
|
|
106
|
-
const notIgnored = warnings
|
|
105
|
+
const notIgnored = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
|
|
107
106
|
const extra = buildExtraWarnings(warnings, isBuild);
|
|
108
107
|
const allWarnings = [...notIgnored, ...extra];
|
|
109
108
|
if (sendViaWS) {
|
|
@@ -131,7 +130,7 @@ function logCompilerWarnings(svelteRequest, warnings, options) {
|
|
|
131
130
|
rawWarnings: warnings
|
|
132
131
|
};
|
|
133
132
|
log.debug(`sending svelte:warnings message for ${svelteRequest.normalizedFilename}`);
|
|
134
|
-
|
|
133
|
+
options.server?.ws?.send("svelte:warnings", message);
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
function ignoreCompilerWarning(warning, isBuild, emitCss) {
|
|
@@ -226,11 +225,11 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
|
|
|
226
225
|
return result;
|
|
227
226
|
}
|
|
228
227
|
function cssChanged(prev, next) {
|
|
229
|
-
return !isCodeEqual(prev
|
|
228
|
+
return !isCodeEqual(prev?.code, next?.code);
|
|
230
229
|
}
|
|
231
230
|
function jsChanged(prev, next, filename) {
|
|
232
|
-
const prevJs = prev
|
|
233
|
-
const nextJs = next
|
|
231
|
+
const prevJs = prev?.code;
|
|
232
|
+
const nextJs = next?.code;
|
|
234
233
|
const isStrictEqual = isCodeEqual(prevJs, nextJs);
|
|
235
234
|
if (isStrictEqual) {
|
|
236
235
|
return false;
|
|
@@ -290,7 +289,6 @@ function toSafe(base64) {
|
|
|
290
289
|
// src/utils/compile.ts
|
|
291
290
|
var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
292
291
|
var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
|
|
293
|
-
var _a, _b, _c;
|
|
294
292
|
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
|
|
295
293
|
const { emitCss = true } = options;
|
|
296
294
|
const dependencies = [];
|
|
@@ -326,11 +324,11 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
|
|
|
326
324
|
compileOptions.sourcemap = preprocessed.map;
|
|
327
325
|
}
|
|
328
326
|
const finalCode = preprocessed ? preprocessed.code : code;
|
|
329
|
-
const dynamicCompileOptions = await
|
|
327
|
+
const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
|
|
330
328
|
filename,
|
|
331
329
|
code: finalCode,
|
|
332
330
|
compileOptions
|
|
333
|
-
})
|
|
331
|
+
});
|
|
334
332
|
if (dynamicCompileOptions && log.debug.enabled) {
|
|
335
333
|
log.debug(
|
|
336
334
|
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
|
|
@@ -360,18 +358,17 @@ import ${JSON.stringify(cssId)};
|
|
|
360
358
|
return {
|
|
361
359
|
filename,
|
|
362
360
|
normalizedFilename,
|
|
363
|
-
lang:
|
|
361
|
+
lang: code.match(scriptLangRE)?.[1] || "js",
|
|
364
362
|
compiled,
|
|
365
363
|
ssr,
|
|
366
364
|
dependencies
|
|
367
365
|
};
|
|
368
366
|
};
|
|
369
367
|
function buildMakeHot(options) {
|
|
370
|
-
var _a, _b;
|
|
371
368
|
const needsMakeHot = options.hot !== false && options.isServe && !options.isProduction;
|
|
372
369
|
if (needsMakeHot) {
|
|
373
|
-
const hotApi =
|
|
374
|
-
const adapter =
|
|
370
|
+
const hotApi = options?.hot?.hotApi;
|
|
371
|
+
const adapter = options?.hot?.adapter;
|
|
375
372
|
return createMakeHot({
|
|
376
373
|
walk,
|
|
377
374
|
hotApi,
|
|
@@ -386,7 +383,7 @@ function createCompileSvelte(options) {
|
|
|
386
383
|
}
|
|
387
384
|
|
|
388
385
|
// src/utils/id.ts
|
|
389
|
-
import { createFilter } from "
|
|
386
|
+
import { createFilter } from "vite";
|
|
390
387
|
import { normalizePath } from "vite";
|
|
391
388
|
import * as fs from "fs";
|
|
392
389
|
var VITE_FS_PREFIX = "/@fs/";
|
|
@@ -485,7 +482,7 @@ var dynamicImportDefault = new Function(
|
|
|
485
482
|
'return import(path + "?t=" + timestamp).then(m => m.default)'
|
|
486
483
|
);
|
|
487
484
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
488
|
-
if (
|
|
485
|
+
if (inlineOptions?.configFile === false) {
|
|
489
486
|
return;
|
|
490
487
|
}
|
|
491
488
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
@@ -534,8 +531,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
534
531
|
}
|
|
535
532
|
}
|
|
536
533
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
|
537
|
-
const root =
|
|
538
|
-
if (inlineOptions
|
|
534
|
+
const root = viteConfig?.root || process.cwd();
|
|
535
|
+
if (inlineOptions?.configFile) {
|
|
539
536
|
const abolutePath = path.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : path.resolve(root, inlineOptions.configFile);
|
|
540
537
|
if (!fs2.existsSync(abolutePath)) {
|
|
541
538
|
throw new Error(`failed to find svelte config file ${abolutePath}.`);
|
|
@@ -681,8 +678,7 @@ function isSvelteComponentLib(pkg) {
|
|
|
681
678
|
return !!pkg.svelte;
|
|
682
679
|
}
|
|
683
680
|
function isSvelteLib(pkg) {
|
|
684
|
-
|
|
685
|
-
return !!((_a = pkg.dependencies) == null ? void 0 : _a.svelte) || !!((_b = pkg.peerDependencies) == null ? void 0 : _b.svelte);
|
|
681
|
+
return !!pkg.dependencies?.svelte || !!pkg.peerDependencies?.svelte;
|
|
686
682
|
}
|
|
687
683
|
var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
688
684
|
"@lukeed/uuid",
|
|
@@ -815,8 +811,7 @@ function esbuildSveltePlugin(options) {
|
|
|
815
811
|
return {
|
|
816
812
|
name: "vite-plugin-svelte:optimize-svelte",
|
|
817
813
|
setup(build) {
|
|
818
|
-
|
|
819
|
-
if ((_a = build.initialOptions.plugins) == null ? void 0 : _a.some((v) => v.name === "vite:dep-scan"))
|
|
814
|
+
if (build.initialOptions.plugins?.some((v) => v.name === "vite:dep-scan"))
|
|
820
815
|
return;
|
|
821
816
|
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
|
|
822
817
|
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
|
|
@@ -833,7 +828,6 @@ function esbuildSveltePlugin(options) {
|
|
|
833
828
|
};
|
|
834
829
|
}
|
|
835
830
|
async function compileSvelte(options, { filename, code }) {
|
|
836
|
-
var _a, _b;
|
|
837
831
|
const compileOptions = {
|
|
838
832
|
...options.compilerOptions,
|
|
839
833
|
css: true,
|
|
@@ -853,11 +847,11 @@ async function compileSvelte(options, { filename, code }) {
|
|
|
853
847
|
compileOptions.sourcemap = preprocessed.map;
|
|
854
848
|
}
|
|
855
849
|
const finalCode = preprocessed ? preprocessed.code : code;
|
|
856
|
-
const dynamicCompileOptions = await
|
|
850
|
+
const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
|
|
857
851
|
filename,
|
|
858
852
|
code: finalCode,
|
|
859
853
|
compileOptions
|
|
860
|
-
})
|
|
854
|
+
});
|
|
861
855
|
if (dynamicCompileOptions && log.debug.enabled) {
|
|
862
856
|
log.debug(`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`);
|
|
863
857
|
}
|
|
@@ -870,9 +864,7 @@ async function compileSvelte(options, { filename, code }) {
|
|
|
870
864
|
}
|
|
871
865
|
|
|
872
866
|
// src/utils/preprocess.ts
|
|
873
|
-
import
|
|
874
|
-
transformWithEsbuild
|
|
875
|
-
} from "vite";
|
|
867
|
+
import * as vite from "vite";
|
|
876
868
|
import MagicString2 from "magic-string";
|
|
877
869
|
import { preprocess as preprocess3 } from "svelte/compiler";
|
|
878
870
|
|
|
@@ -900,7 +892,7 @@ async function buildMagicString(from, to, options) {
|
|
|
900
892
|
const diff = diffs[i];
|
|
901
893
|
const nextDiff = diffs[i + 1];
|
|
902
894
|
if (diff[0] === DIFF_DELETE) {
|
|
903
|
-
if (
|
|
895
|
+
if (nextDiff?.[0] === DIFF_INSERT) {
|
|
904
896
|
m.overwrite(pos, pos + diff[1].length, nextDiff[1]);
|
|
905
897
|
i++;
|
|
906
898
|
} else {
|
|
@@ -933,7 +925,7 @@ function createViteScriptPreprocessor() {
|
|
|
933
925
|
const lang = attributes.lang;
|
|
934
926
|
if (!supportedScriptLangs.includes(lang))
|
|
935
927
|
return;
|
|
936
|
-
const transformResult = await transformWithEsbuild(content, filename, {
|
|
928
|
+
const transformResult = await vite.transformWithEsbuild(content, filename, {
|
|
937
929
|
loader: lang,
|
|
938
930
|
target: "esnext",
|
|
939
931
|
tsconfigRaw: {
|
|
@@ -950,34 +942,39 @@ function createViteScriptPreprocessor() {
|
|
|
950
942
|
};
|
|
951
943
|
}
|
|
952
944
|
function createViteStylePreprocessor(config) {
|
|
953
|
-
const
|
|
954
|
-
const plugin = config.plugins.find((p) => p.name === pluginName);
|
|
955
|
-
if (!plugin) {
|
|
956
|
-
throw new Error(`failed to find plugin ${pluginName}`);
|
|
957
|
-
}
|
|
958
|
-
if (!plugin.transform) {
|
|
959
|
-
throw new Error(`plugin ${pluginName} has no transform`);
|
|
960
|
-
}
|
|
961
|
-
const pluginTransform = plugin.transform.bind(null);
|
|
945
|
+
const transform = getCssTransformFn(config);
|
|
962
946
|
return async ({ attributes, content, filename = "" }) => {
|
|
963
|
-
var _a, _b;
|
|
964
947
|
const lang = attributes.lang;
|
|
965
948
|
if (!supportedStyleLangs.includes(lang))
|
|
966
949
|
return;
|
|
967
950
|
const moduleId = `${filename}.${lang}`;
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
);
|
|
972
|
-
if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
|
|
973
|
-
transformResult.map.sources[0] = path3.basename(filename);
|
|
951
|
+
const result = await transform(content, moduleId);
|
|
952
|
+
if (result.map?.sources?.[0] === moduleId) {
|
|
953
|
+
result.map.sources[0] = path3.basename(filename);
|
|
974
954
|
}
|
|
975
955
|
return {
|
|
976
|
-
code:
|
|
977
|
-
map:
|
|
956
|
+
code: result.code,
|
|
957
|
+
map: result.map ?? void 0
|
|
978
958
|
};
|
|
979
959
|
};
|
|
980
960
|
}
|
|
961
|
+
function getCssTransformFn(config) {
|
|
962
|
+
if (vite.preprocessCSS) {
|
|
963
|
+
return async (code, filename) => {
|
|
964
|
+
return vite.preprocessCSS(code, filename, config);
|
|
965
|
+
};
|
|
966
|
+
} else {
|
|
967
|
+
const pluginName = "vite:css";
|
|
968
|
+
const plugin = config.plugins.find((p) => p.name === pluginName);
|
|
969
|
+
if (!plugin) {
|
|
970
|
+
throw new Error(`failed to find plugin ${pluginName}`);
|
|
971
|
+
}
|
|
972
|
+
if (!plugin.transform) {
|
|
973
|
+
throw new Error(`plugin ${pluginName} has no transform`);
|
|
974
|
+
}
|
|
975
|
+
return plugin.transform.bind(null);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
981
978
|
function createVitePreprocessorGroup(config) {
|
|
982
979
|
return {
|
|
983
980
|
markup({ content, filename }) {
|
|
@@ -1008,14 +1005,13 @@ function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
|
1008
1005
|
};
|
|
1009
1006
|
}
|
|
1010
1007
|
function buildExtraPreprocessors(options, config) {
|
|
1011
|
-
var _a, _b;
|
|
1012
1008
|
const prependPreprocessors = [];
|
|
1013
1009
|
const appendPreprocessors = [];
|
|
1014
|
-
if (
|
|
1010
|
+
if (options.experimental?.useVitePreprocess) {
|
|
1015
1011
|
log.debug("adding vite preprocessor");
|
|
1016
1012
|
prependPreprocessors.push(createVitePreprocessorGroup(config));
|
|
1017
1013
|
}
|
|
1018
|
-
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p
|
|
1014
|
+
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
|
|
1019
1015
|
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
1020
1016
|
log.warn(
|
|
1021
1017
|
`The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated.map((p) => p.name).join(", ")}`
|
|
@@ -1033,13 +1029,10 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1033
1029
|
}
|
|
1034
1030
|
});
|
|
1035
1031
|
}
|
|
1036
|
-
const pluginsWithPreprocessors = config.plugins.filter((p) =>
|
|
1037
|
-
var _a2;
|
|
1038
|
-
return (_a2 = p == null ? void 0 : p.api) == null ? void 0 : _a2.sveltePreprocess;
|
|
1039
|
-
});
|
|
1032
|
+
const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
|
|
1040
1033
|
const ignored = [], included = [];
|
|
1041
1034
|
for (const p of pluginsWithPreprocessors) {
|
|
1042
|
-
if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) &&
|
|
1035
|
+
if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && options.ignorePluginPreprocessors?.includes(p.name)) {
|
|
1043
1036
|
ignored.push(p);
|
|
1044
1037
|
} else {
|
|
1045
1038
|
included.push(p);
|
|
@@ -1062,7 +1055,6 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1062
1055
|
return { prependPreprocessors, appendPreprocessors };
|
|
1063
1056
|
}
|
|
1064
1057
|
function addExtraPreprocessors(options, config) {
|
|
1065
|
-
var _a;
|
|
1066
1058
|
const { prependPreprocessors, appendPreprocessors } = buildExtraPreprocessors(options, config);
|
|
1067
1059
|
if (prependPreprocessors.length > 0 || appendPreprocessors.length > 0) {
|
|
1068
1060
|
if (!options.preprocess) {
|
|
@@ -1074,7 +1066,7 @@ function addExtraPreprocessors(options, config) {
|
|
|
1074
1066
|
options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
|
|
1075
1067
|
}
|
|
1076
1068
|
}
|
|
1077
|
-
const generateMissingSourceMaps = !!
|
|
1069
|
+
const generateMissingSourceMaps = !!options.experimental?.generateMissingPreprocessorSourcemaps;
|
|
1078
1070
|
if (options.preprocess && generateMissingSourceMaps) {
|
|
1079
1071
|
options.preprocess = Array.isArray(options.preprocess) ? options.preprocess.map((p, i) => validateSourceMapOutputWrapper(p, i)) : validateSourceMapOutputWrapper(options.preprocess, 0);
|
|
1080
1072
|
}
|
|
@@ -1083,7 +1075,6 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1083
1075
|
const wrapper = {};
|
|
1084
1076
|
for (const [processorType, processorFn] of Object.entries(group)) {
|
|
1085
1077
|
wrapper[processorType] = async (options) => {
|
|
1086
|
-
var _a;
|
|
1087
1078
|
const result = await processorFn(options);
|
|
1088
1079
|
if (result && result.code !== options.content) {
|
|
1089
1080
|
let invalidMap = false;
|
|
@@ -1097,7 +1088,7 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1097
1088
|
processor: processorFn.toString()
|
|
1098
1089
|
}
|
|
1099
1090
|
);
|
|
1100
|
-
} else if (
|
|
1091
|
+
} else if (result.map?.mappings === "") {
|
|
1101
1092
|
invalidMap = true;
|
|
1102
1093
|
log.warn.enabled && log.warn.once(
|
|
1103
1094
|
`preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
|
|
@@ -1137,6 +1128,7 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
|
1137
1128
|
"hot",
|
|
1138
1129
|
"ignorePluginPreprocessors",
|
|
1139
1130
|
"disableDependencyReinclusion",
|
|
1131
|
+
"prebundleSvelteLibraries",
|
|
1140
1132
|
"experimental"
|
|
1141
1133
|
]);
|
|
1142
1134
|
var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
|
|
@@ -1231,7 +1223,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1231
1223
|
inlineOptions,
|
|
1232
1224
|
extraOptions
|
|
1233
1225
|
);
|
|
1234
|
-
if (svelteConfig
|
|
1226
|
+
if (svelteConfig?.configFile) {
|
|
1235
1227
|
merged.configFile = svelteConfig.configFile;
|
|
1236
1228
|
}
|
|
1237
1229
|
return merged;
|
|
@@ -1246,11 +1238,10 @@ function mergeConfigs(...configs) {
|
|
|
1246
1238
|
return result;
|
|
1247
1239
|
}
|
|
1248
1240
|
function resolveOptions(preResolveOptions2, viteConfig) {
|
|
1249
|
-
var _a;
|
|
1250
1241
|
const defaultOptions = {
|
|
1251
1242
|
hot: viteConfig.isProduction ? false : {
|
|
1252
1243
|
injectCss: !preResolveOptions2.emitCss,
|
|
1253
|
-
partialAccept: !!
|
|
1244
|
+
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
|
|
1254
1245
|
},
|
|
1255
1246
|
compilerOptions: {
|
|
1256
1247
|
css: !preResolveOptions2.emitCss,
|
|
@@ -1263,6 +1254,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1263
1254
|
};
|
|
1264
1255
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1265
1256
|
removeIgnoredOptions(merged);
|
|
1257
|
+
handleDeprecatedOptions(merged);
|
|
1266
1258
|
addSvelteKitOptions(merged);
|
|
1267
1259
|
addExtraPreprocessors(merged, viteConfig);
|
|
1268
1260
|
enforceOptionsForHmr(merged);
|
|
@@ -1339,9 +1331,8 @@ function removeIgnoredOptions(options) {
|
|
|
1339
1331
|
}
|
|
1340
1332
|
}
|
|
1341
1333
|
function addSvelteKitOptions(options) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
const kit_browser_hydrate = (_a = options.kit.browser) == null ? void 0 : _a.hydrate;
|
|
1334
|
+
if (options?.kit != null) {
|
|
1335
|
+
const kit_browser_hydrate = options.kit.browser?.hydrate;
|
|
1345
1336
|
const hydratable = kit_browser_hydrate !== false;
|
|
1346
1337
|
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1347
1338
|
log.warn(
|
|
@@ -1352,11 +1343,18 @@ function addSvelteKitOptions(options) {
|
|
|
1352
1343
|
options.compilerOptions.hydratable = hydratable;
|
|
1353
1344
|
}
|
|
1354
1345
|
}
|
|
1346
|
+
function handleDeprecatedOptions(options) {
|
|
1347
|
+
if (options.experimental?.prebundleSvelteLibraries) {
|
|
1348
|
+
options.prebundleSvelteLibraries = options.experimental?.prebundleSvelteLibraries;
|
|
1349
|
+
log.warn(
|
|
1350
|
+
"experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1355
1354
|
function resolveViteRoot(viteConfig) {
|
|
1356
1355
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1357
1356
|
}
|
|
1358
1357
|
function buildExtraViteConfig(options, config) {
|
|
1359
|
-
var _a, _b;
|
|
1360
1358
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1361
1359
|
const extraViteConfig = {
|
|
1362
1360
|
resolve: {
|
|
@@ -1369,7 +1367,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1369
1367
|
options,
|
|
1370
1368
|
config.optimizeDeps
|
|
1371
1369
|
);
|
|
1372
|
-
if (
|
|
1370
|
+
if (options.prebundleSvelteLibraries) {
|
|
1373
1371
|
extraViteConfig.optimizeDeps = {
|
|
1374
1372
|
...extraViteConfig.optimizeDeps,
|
|
1375
1373
|
extensions: options.extensions ?? [".svelte"],
|
|
@@ -1380,23 +1378,18 @@ function buildExtraViteConfig(options, config) {
|
|
|
1380
1378
|
};
|
|
1381
1379
|
}
|
|
1382
1380
|
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1383
|
-
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) &&
|
|
1381
|
+
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && config.experimental?.hmrPartialAccept !== false) {
|
|
1384
1382
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1385
1383
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1386
1384
|
}
|
|
1387
1385
|
return extraViteConfig;
|
|
1388
1386
|
}
|
|
1389
1387
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1390
|
-
var _a;
|
|
1391
1388
|
const include = [];
|
|
1392
1389
|
const exclude = ["svelte-hmr"];
|
|
1393
|
-
const isIncluded = (dep) =>
|
|
1394
|
-
var _a2;
|
|
1395
|
-
return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
|
|
1396
|
-
};
|
|
1390
|
+
const isIncluded = (dep) => include.includes(dep) || optimizeDeps?.include?.includes(dep);
|
|
1397
1391
|
const isExcluded = (dep) => {
|
|
1398
|
-
|
|
1399
|
-
return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1392
|
+
return exclude.includes(dep) || optimizeDeps?.exclude?.some((id) => dep === id || id.startsWith(`${dep}/`));
|
|
1400
1393
|
};
|
|
1401
1394
|
if (!isExcluded("svelte")) {
|
|
1402
1395
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1407,7 +1400,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1407
1400
|
} else {
|
|
1408
1401
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1409
1402
|
}
|
|
1410
|
-
if (
|
|
1403
|
+
if (options.prebundleSvelteLibraries) {
|
|
1411
1404
|
return { include, exclude };
|
|
1412
1405
|
}
|
|
1413
1406
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1434,17 +1427,13 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1434
1427
|
return { include, exclude };
|
|
1435
1428
|
}
|
|
1436
1429
|
function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
1437
|
-
var _a, _b;
|
|
1438
1430
|
const noExternal = [];
|
|
1439
|
-
if (!
|
|
1431
|
+
if (!config.ssr?.external?.includes("svelte")) {
|
|
1440
1432
|
noExternal.push("svelte", /^svelte\//);
|
|
1441
1433
|
}
|
|
1442
1434
|
noExternal.push(
|
|
1443
1435
|
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
|
|
1444
|
-
(x) =>
|
|
1445
|
-
var _a2, _b2;
|
|
1446
|
-
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
|
|
1447
|
-
}
|
|
1436
|
+
(x) => !config.ssr?.external?.includes(x)
|
|
1448
1437
|
)
|
|
1449
1438
|
);
|
|
1450
1439
|
const ssr = {
|
|
@@ -1455,17 +1444,13 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1455
1444
|
ssr.external = Array.from(
|
|
1456
1445
|
new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
|
|
1457
1446
|
).filter(
|
|
1458
|
-
(dep) =>
|
|
1459
|
-
var _a2, _b2;
|
|
1460
|
-
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
|
|
1461
|
-
}
|
|
1447
|
+
(dep) => !ssr.noExternal.includes(dep) && !config.ssr?.external?.includes(dep)
|
|
1462
1448
|
);
|
|
1463
1449
|
}
|
|
1464
1450
|
return ssr;
|
|
1465
1451
|
}
|
|
1466
1452
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1467
|
-
|
|
1468
|
-
const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
|
|
1453
|
+
const facadeEsbuildSveltePlugin = viteConfig.optimizeDeps.esbuildOptions?.plugins?.find(
|
|
1469
1454
|
(plugin) => plugin.name === facadeEsbuildSveltePluginName
|
|
1470
1455
|
);
|
|
1471
1456
|
if (facadeEsbuildSveltePlugin) {
|
|
@@ -1773,9 +1758,8 @@ function svelteInspector() {
|
|
|
1773
1758
|
apply: "serve",
|
|
1774
1759
|
enforce: "pre",
|
|
1775
1760
|
configResolved(config) {
|
|
1776
|
-
var _a, _b, _c;
|
|
1777
1761
|
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1778
|
-
if (
|
|
1762
|
+
if (vps?.api?.options?.experimental?.inspector) {
|
|
1779
1763
|
inspectorOptions = {
|
|
1780
1764
|
...defaultInspectorOptions,
|
|
1781
1765
|
...vps.api.options.experimental.inspector
|
|
@@ -1793,7 +1777,7 @@ function svelteInspector() {
|
|
|
1793
1777
|
}
|
|
1794
1778
|
},
|
|
1795
1779
|
async resolveId(importee, importer, options) {
|
|
1796
|
-
if (
|
|
1780
|
+
if (options?.ssr || disabled) {
|
|
1797
1781
|
return;
|
|
1798
1782
|
}
|
|
1799
1783
|
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
@@ -1805,7 +1789,7 @@ function svelteInspector() {
|
|
|
1805
1789
|
}
|
|
1806
1790
|
},
|
|
1807
1791
|
async load(id, options) {
|
|
1808
|
-
if (
|
|
1792
|
+
if (options?.ssr || disabled) {
|
|
1809
1793
|
return;
|
|
1810
1794
|
}
|
|
1811
1795
|
if (id === "virtual:svelte-inspector-options") {
|
|
@@ -1820,7 +1804,7 @@ function svelteInspector() {
|
|
|
1820
1804
|
}
|
|
1821
1805
|
},
|
|
1822
1806
|
transform(code, id, options) {
|
|
1823
|
-
if (
|
|
1807
|
+
if (options?.ssr || disabled || !appendTo) {
|
|
1824
1808
|
return;
|
|
1825
1809
|
}
|
|
1826
1810
|
if (id.endsWith(appendTo)) {
|
|
@@ -1888,8 +1872,7 @@ function svelte(inlineOptions) {
|
|
|
1888
1872
|
log.debug("resolved options", options);
|
|
1889
1873
|
},
|
|
1890
1874
|
async buildStart() {
|
|
1891
|
-
|
|
1892
|
-
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1875
|
+
if (!options.prebundleSvelteLibraries)
|
|
1893
1876
|
return;
|
|
1894
1877
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1895
1878
|
if (isSvelteMetadataChanged) {
|
|
@@ -1901,7 +1884,7 @@ function svelte(inlineOptions) {
|
|
|
1901
1884
|
setupWatchers(options, cache, requestParser);
|
|
1902
1885
|
},
|
|
1903
1886
|
load(id, opts) {
|
|
1904
|
-
const ssr = !!
|
|
1887
|
+
const ssr = !!opts?.ssr;
|
|
1905
1888
|
const svelteRequest = requestParser(id, !!ssr);
|
|
1906
1889
|
if (svelteRequest) {
|
|
1907
1890
|
const { filename, query } = svelteRequest;
|
|
@@ -1919,9 +1902,9 @@ function svelte(inlineOptions) {
|
|
|
1919
1902
|
}
|
|
1920
1903
|
},
|
|
1921
1904
|
async resolveId(importee, importer, opts) {
|
|
1922
|
-
const ssr = !!
|
|
1905
|
+
const ssr = !!opts?.ssr;
|
|
1923
1906
|
const svelteRequest = requestParser(importee, ssr);
|
|
1924
|
-
if (svelteRequest
|
|
1907
|
+
if (svelteRequest?.query.svelte) {
|
|
1925
1908
|
if (svelteRequest.query.type === "style") {
|
|
1926
1909
|
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
1927
1910
|
return svelteRequest.cssId;
|
|
@@ -1963,8 +1946,7 @@ function svelte(inlineOptions) {
|
|
|
1963
1946
|
}
|
|
1964
1947
|
},
|
|
1965
1948
|
async transform(code, id, opts) {
|
|
1966
|
-
|
|
1967
|
-
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1949
|
+
const ssr = !!opts?.ssr;
|
|
1968
1950
|
const svelteRequest = requestParser(id, ssr);
|
|
1969
1951
|
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1970
1952
|
return;
|
|
@@ -1978,7 +1960,7 @@ function svelte(inlineOptions) {
|
|
|
1978
1960
|
}
|
|
1979
1961
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
1980
1962
|
cache.update(compileData);
|
|
1981
|
-
if (
|
|
1963
|
+
if (compileData.dependencies?.length && options.server) {
|
|
1982
1964
|
compileData.dependencies.forEach((d) => {
|
|
1983
1965
|
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1984
1966
|
});
|