@sveltejs/vite-plugin-svelte 1.1.0 → 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 +77 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -99
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/utils/preprocess.ts +33 -26
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,
|
|
@@ -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`,
|
|
@@ -1232,7 +1223,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1232
1223
|
inlineOptions,
|
|
1233
1224
|
extraOptions
|
|
1234
1225
|
);
|
|
1235
|
-
if (svelteConfig
|
|
1226
|
+
if (svelteConfig?.configFile) {
|
|
1236
1227
|
merged.configFile = svelteConfig.configFile;
|
|
1237
1228
|
}
|
|
1238
1229
|
return merged;
|
|
@@ -1247,11 +1238,10 @@ function mergeConfigs(...configs) {
|
|
|
1247
1238
|
return result;
|
|
1248
1239
|
}
|
|
1249
1240
|
function resolveOptions(preResolveOptions2, viteConfig) {
|
|
1250
|
-
var _a;
|
|
1251
1241
|
const defaultOptions = {
|
|
1252
1242
|
hot: viteConfig.isProduction ? false : {
|
|
1253
1243
|
injectCss: !preResolveOptions2.emitCss,
|
|
1254
|
-
partialAccept: !!
|
|
1244
|
+
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
|
|
1255
1245
|
},
|
|
1256
1246
|
compilerOptions: {
|
|
1257
1247
|
css: !preResolveOptions2.emitCss,
|
|
@@ -1341,9 +1331,8 @@ function removeIgnoredOptions(options) {
|
|
|
1341
1331
|
}
|
|
1342
1332
|
}
|
|
1343
1333
|
function addSvelteKitOptions(options) {
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
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;
|
|
1347
1336
|
const hydratable = kit_browser_hydrate !== false;
|
|
1348
1337
|
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1349
1338
|
log.warn(
|
|
@@ -1355,9 +1344,8 @@ function addSvelteKitOptions(options) {
|
|
|
1355
1344
|
}
|
|
1356
1345
|
}
|
|
1357
1346
|
function handleDeprecatedOptions(options) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
options.prebundleSvelteLibraries = (_b = options.experimental) == null ? void 0 : _b.prebundleSvelteLibraries;
|
|
1347
|
+
if (options.experimental?.prebundleSvelteLibraries) {
|
|
1348
|
+
options.prebundleSvelteLibraries = options.experimental?.prebundleSvelteLibraries;
|
|
1361
1349
|
log.warn(
|
|
1362
1350
|
"experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
|
|
1363
1351
|
);
|
|
@@ -1367,7 +1355,6 @@ function resolveViteRoot(viteConfig) {
|
|
|
1367
1355
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1368
1356
|
}
|
|
1369
1357
|
function buildExtraViteConfig(options, config) {
|
|
1370
|
-
var _a;
|
|
1371
1358
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1372
1359
|
const extraViteConfig = {
|
|
1373
1360
|
resolve: {
|
|
@@ -1391,7 +1378,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1391
1378
|
};
|
|
1392
1379
|
}
|
|
1393
1380
|
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1394
|
-
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) {
|
|
1395
1382
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1396
1383
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1397
1384
|
}
|
|
@@ -1400,13 +1387,9 @@ function buildExtraViteConfig(options, config) {
|
|
|
1400
1387
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1401
1388
|
const include = [];
|
|
1402
1389
|
const exclude = ["svelte-hmr"];
|
|
1403
|
-
const isIncluded = (dep) =>
|
|
1404
|
-
var _a;
|
|
1405
|
-
return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
|
|
1406
|
-
};
|
|
1390
|
+
const isIncluded = (dep) => include.includes(dep) || optimizeDeps?.include?.includes(dep);
|
|
1407
1391
|
const isExcluded = (dep) => {
|
|
1408
|
-
|
|
1409
|
-
return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1392
|
+
return exclude.includes(dep) || optimizeDeps?.exclude?.some((id) => dep === id || id.startsWith(`${dep}/`));
|
|
1410
1393
|
};
|
|
1411
1394
|
if (!isExcluded("svelte")) {
|
|
1412
1395
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1444,17 +1427,13 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1444
1427
|
return { include, exclude };
|
|
1445
1428
|
}
|
|
1446
1429
|
function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
1447
|
-
var _a, _b;
|
|
1448
1430
|
const noExternal = [];
|
|
1449
|
-
if (!
|
|
1431
|
+
if (!config.ssr?.external?.includes("svelte")) {
|
|
1450
1432
|
noExternal.push("svelte", /^svelte\//);
|
|
1451
1433
|
}
|
|
1452
1434
|
noExternal.push(
|
|
1453
1435
|
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
|
|
1454
|
-
(x) =>
|
|
1455
|
-
var _a2, _b2;
|
|
1456
|
-
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
|
|
1457
|
-
}
|
|
1436
|
+
(x) => !config.ssr?.external?.includes(x)
|
|
1458
1437
|
)
|
|
1459
1438
|
);
|
|
1460
1439
|
const ssr = {
|
|
@@ -1465,17 +1444,13 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1465
1444
|
ssr.external = Array.from(
|
|
1466
1445
|
new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
|
|
1467
1446
|
).filter(
|
|
1468
|
-
(dep) =>
|
|
1469
|
-
var _a2, _b2;
|
|
1470
|
-
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
|
|
1471
|
-
}
|
|
1447
|
+
(dep) => !ssr.noExternal.includes(dep) && !config.ssr?.external?.includes(dep)
|
|
1472
1448
|
);
|
|
1473
1449
|
}
|
|
1474
1450
|
return ssr;
|
|
1475
1451
|
}
|
|
1476
1452
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1477
|
-
|
|
1478
|
-
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(
|
|
1479
1454
|
(plugin) => plugin.name === facadeEsbuildSveltePluginName
|
|
1480
1455
|
);
|
|
1481
1456
|
if (facadeEsbuildSveltePlugin) {
|
|
@@ -1783,9 +1758,8 @@ function svelteInspector() {
|
|
|
1783
1758
|
apply: "serve",
|
|
1784
1759
|
enforce: "pre",
|
|
1785
1760
|
configResolved(config) {
|
|
1786
|
-
var _a, _b, _c;
|
|
1787
1761
|
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1788
|
-
if (
|
|
1762
|
+
if (vps?.api?.options?.experimental?.inspector) {
|
|
1789
1763
|
inspectorOptions = {
|
|
1790
1764
|
...defaultInspectorOptions,
|
|
1791
1765
|
...vps.api.options.experimental.inspector
|
|
@@ -1803,7 +1777,7 @@ function svelteInspector() {
|
|
|
1803
1777
|
}
|
|
1804
1778
|
},
|
|
1805
1779
|
async resolveId(importee, importer, options) {
|
|
1806
|
-
if (
|
|
1780
|
+
if (options?.ssr || disabled) {
|
|
1807
1781
|
return;
|
|
1808
1782
|
}
|
|
1809
1783
|
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
@@ -1815,7 +1789,7 @@ function svelteInspector() {
|
|
|
1815
1789
|
}
|
|
1816
1790
|
},
|
|
1817
1791
|
async load(id, options) {
|
|
1818
|
-
if (
|
|
1792
|
+
if (options?.ssr || disabled) {
|
|
1819
1793
|
return;
|
|
1820
1794
|
}
|
|
1821
1795
|
if (id === "virtual:svelte-inspector-options") {
|
|
@@ -1830,7 +1804,7 @@ function svelteInspector() {
|
|
|
1830
1804
|
}
|
|
1831
1805
|
},
|
|
1832
1806
|
transform(code, id, options) {
|
|
1833
|
-
if (
|
|
1807
|
+
if (options?.ssr || disabled || !appendTo) {
|
|
1834
1808
|
return;
|
|
1835
1809
|
}
|
|
1836
1810
|
if (id.endsWith(appendTo)) {
|
|
@@ -1910,7 +1884,7 @@ function svelte(inlineOptions) {
|
|
|
1910
1884
|
setupWatchers(options, cache, requestParser);
|
|
1911
1885
|
},
|
|
1912
1886
|
load(id, opts) {
|
|
1913
|
-
const ssr = !!
|
|
1887
|
+
const ssr = !!opts?.ssr;
|
|
1914
1888
|
const svelteRequest = requestParser(id, !!ssr);
|
|
1915
1889
|
if (svelteRequest) {
|
|
1916
1890
|
const { filename, query } = svelteRequest;
|
|
@@ -1928,9 +1902,9 @@ function svelte(inlineOptions) {
|
|
|
1928
1902
|
}
|
|
1929
1903
|
},
|
|
1930
1904
|
async resolveId(importee, importer, opts) {
|
|
1931
|
-
const ssr = !!
|
|
1905
|
+
const ssr = !!opts?.ssr;
|
|
1932
1906
|
const svelteRequest = requestParser(importee, ssr);
|
|
1933
|
-
if (svelteRequest
|
|
1907
|
+
if (svelteRequest?.query.svelte) {
|
|
1934
1908
|
if (svelteRequest.query.type === "style") {
|
|
1935
1909
|
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
1936
1910
|
return svelteRequest.cssId;
|
|
@@ -1972,8 +1946,7 @@ function svelte(inlineOptions) {
|
|
|
1972
1946
|
}
|
|
1973
1947
|
},
|
|
1974
1948
|
async transform(code, id, opts) {
|
|
1975
|
-
|
|
1976
|
-
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1949
|
+
const ssr = !!opts?.ssr;
|
|
1977
1950
|
const svelteRequest = requestParser(id, ssr);
|
|
1978
1951
|
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1979
1952
|
return;
|
|
@@ -1987,7 +1960,7 @@ function svelte(inlineOptions) {
|
|
|
1987
1960
|
}
|
|
1988
1961
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
1989
1962
|
cache.update(compileData);
|
|
1990
|
-
if (
|
|
1963
|
+
if (compileData.dependencies?.length && options.server) {
|
|
1991
1964
|
compileData.dependencies.forEach((d) => {
|
|
1992
1965
|
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1993
1966
|
});
|