@sveltejs/vite-plugin-svelte 1.0.1 → 1.0.2
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 +198 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +193 -69
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/src/handle-hot-update.ts +1 -1
- package/src/ui/inspector/plugin.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/index.ts
|
|
@@ -28,7 +31,7 @@ __export(src_exports, {
|
|
|
28
31
|
});
|
|
29
32
|
module.exports = __toCommonJS(src_exports);
|
|
30
33
|
|
|
31
|
-
// ../../node_modules/.pnpm/tsup@6.
|
|
34
|
+
// ../../node_modules/.pnpm/tsup@6.2.2/node_modules/tsup/assets/cjs_shims.js
|
|
32
35
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
33
36
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
34
37
|
|
|
@@ -245,7 +248,9 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
|
|
|
245
248
|
ssrModulesToInvalidate.forEach((moduleNode) => server.moduleGraph.invalidateModule(moduleNode));
|
|
246
249
|
}
|
|
247
250
|
if (result.length > 0) {
|
|
248
|
-
log.debug(
|
|
251
|
+
log.debug(
|
|
252
|
+
`handleHotUpdate for ${svelteRequest.id} result: ${result.map((m) => m.id).join(", ")}`
|
|
253
|
+
);
|
|
249
254
|
}
|
|
250
255
|
return result;
|
|
251
256
|
}
|
|
@@ -261,7 +266,9 @@ function jsChanged(prev, next, filename) {
|
|
|
261
266
|
}
|
|
262
267
|
const isLooseEqual = isCodeEqual(normalizeJsCode(prevJs), normalizeJsCode(nextJs));
|
|
263
268
|
if (!isStrictEqual && isLooseEqual) {
|
|
264
|
-
log.warn(
|
|
269
|
+
log.warn(
|
|
270
|
+
`ignoring compiler output js change for ${filename} as it is equal to previous output after normalization`
|
|
271
|
+
);
|
|
265
272
|
}
|
|
266
273
|
return !isLooseEqual;
|
|
267
274
|
}
|
|
@@ -354,7 +361,9 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
|
|
|
354
361
|
compileOptions
|
|
355
362
|
}));
|
|
356
363
|
if (dynamicCompileOptions && log.debug.enabled) {
|
|
357
|
-
log.debug(
|
|
364
|
+
log.debug(
|
|
365
|
+
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
|
|
366
|
+
);
|
|
358
367
|
}
|
|
359
368
|
const finalCompileOptions = dynamicCompileOptions ? {
|
|
360
369
|
...compileOptions,
|
|
@@ -497,7 +506,11 @@ var knownSvelteConfigNames = [
|
|
|
497
506
|
"svelte.config.cjs",
|
|
498
507
|
"svelte.config.mjs"
|
|
499
508
|
];
|
|
500
|
-
var dynamicImportDefault = new Function(
|
|
509
|
+
var dynamicImportDefault = new Function(
|
|
510
|
+
"path",
|
|
511
|
+
"timestamp",
|
|
512
|
+
'return import(path + "?t=" + timestamp).then(m => m.default)'
|
|
513
|
+
);
|
|
501
514
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
502
515
|
if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
|
|
503
516
|
return;
|
|
@@ -507,7 +520,10 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
507
520
|
let err;
|
|
508
521
|
if (configFile.endsWith(".js") || configFile.endsWith(".mjs")) {
|
|
509
522
|
try {
|
|
510
|
-
const result = await dynamicImportDefault(
|
|
523
|
+
const result = await dynamicImportDefault(
|
|
524
|
+
(0, import_url.pathToFileURL)(configFile).href,
|
|
525
|
+
import_fs.default.statSync(configFile).mtimeMs
|
|
526
|
+
);
|
|
511
527
|
if (result != null) {
|
|
512
528
|
return {
|
|
513
529
|
...result,
|
|
@@ -558,7 +574,10 @@ function findConfigToLoad(viteConfig, inlineOptions) {
|
|
|
558
574
|
log.debug(`no svelte config found at ${root}`);
|
|
559
575
|
return;
|
|
560
576
|
} else if (existingKnownConfigFiles.length > 1) {
|
|
561
|
-
log.warn(
|
|
577
|
+
log.warn(
|
|
578
|
+
`found more than one svelte config file, using ${existingKnownConfigFiles[0]}. you should only have one!`,
|
|
579
|
+
existingKnownConfigFiles
|
|
580
|
+
);
|
|
562
581
|
}
|
|
563
582
|
return existingKnownConfigFiles[0];
|
|
564
583
|
}
|
|
@@ -627,7 +646,10 @@ function getSvelteDependencies(deps, pkgDir, path9 = []) {
|
|
|
627
646
|
let dependencyNames = Object.keys(pkg.dependencies);
|
|
628
647
|
const circular = dependencyNames.filter((name) => path9.includes(name));
|
|
629
648
|
if (circular.length > 0) {
|
|
630
|
-
log.warn.enabled && log.warn(
|
|
649
|
+
log.warn.enabled && log.warn(
|
|
650
|
+
`skipping circular svelte dependencies in automated vite optimizeDeps handling`,
|
|
651
|
+
circular.map((x) => path9.concat(x).join(">"))
|
|
652
|
+
);
|
|
631
653
|
dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
|
|
632
654
|
}
|
|
633
655
|
if (path9.length === 3) {
|
|
@@ -729,7 +751,9 @@ var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
|
|
|
729
751
|
"vite-plugin-"
|
|
730
752
|
];
|
|
731
753
|
function is_common_without_svelte_field(dependency) {
|
|
732
|
-
return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
|
|
754
|
+
return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
|
|
755
|
+
(prefix2) => prefix2.startsWith("@") ? dependency.startsWith(prefix2) : dependency.substring(dependency.lastIndexOf("/") + 1).startsWith(prefix2)
|
|
756
|
+
);
|
|
733
757
|
}
|
|
734
758
|
function needsOptimization(dep, localRequire) {
|
|
735
759
|
const depData = resolveDependencyData(dep, localRequire);
|
|
@@ -887,7 +911,9 @@ async function buildMagicString(from, to, options) {
|
|
|
887
911
|
DIFF_INSERT = dmpPkg.DIFF_INSERT;
|
|
888
912
|
DIFF_DELETE = dmpPkg.DIFF_DELETE;
|
|
889
913
|
} catch (e) {
|
|
890
|
-
log.error.once(
|
|
914
|
+
log.error.once(
|
|
915
|
+
'Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.'
|
|
916
|
+
);
|
|
891
917
|
return null;
|
|
892
918
|
}
|
|
893
919
|
const dmp = new diff_match_patch();
|
|
@@ -963,7 +989,10 @@ function createViteStylePreprocessor(config) {
|
|
|
963
989
|
if (!supportedStyleLangs.includes(lang))
|
|
964
990
|
return;
|
|
965
991
|
const moduleId = `${filename}.${lang}`;
|
|
966
|
-
const transformResult = await pluginTransform(
|
|
992
|
+
const transformResult = await pluginTransform(
|
|
993
|
+
content,
|
|
994
|
+
moduleId
|
|
995
|
+
);
|
|
967
996
|
if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
|
|
968
997
|
transformResult.map.sources[0] = import_path3.default.basename(filename);
|
|
969
998
|
}
|
|
@@ -976,10 +1005,14 @@ function createViteStylePreprocessor(config) {
|
|
|
976
1005
|
function createVitePreprocessorGroup(config) {
|
|
977
1006
|
return {
|
|
978
1007
|
markup({ content, filename }) {
|
|
979
|
-
return (0, import_compiler3.preprocess)(
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1008
|
+
return (0, import_compiler3.preprocess)(
|
|
1009
|
+
content,
|
|
1010
|
+
{
|
|
1011
|
+
script: createViteScriptPreprocessor(),
|
|
1012
|
+
style: createViteStylePreprocessor(config)
|
|
1013
|
+
},
|
|
1014
|
+
{ filename }
|
|
1015
|
+
);
|
|
983
1016
|
}
|
|
984
1017
|
};
|
|
985
1018
|
}
|
|
@@ -1008,7 +1041,9 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1008
1041
|
}
|
|
1009
1042
|
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p == null ? void 0 : p.sveltePreprocess);
|
|
1010
1043
|
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
1011
|
-
log.warn(
|
|
1044
|
+
log.warn(
|
|
1045
|
+
`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(", ")}`
|
|
1046
|
+
);
|
|
1012
1047
|
pluginsWithPreprocessorsDeprecated.forEach((p) => {
|
|
1013
1048
|
if (!p.api) {
|
|
1014
1049
|
p.api = {};
|
|
@@ -1016,7 +1051,9 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1016
1051
|
if (p.api.sveltePreprocess === void 0) {
|
|
1017
1052
|
p.api.sveltePreprocess = p.sveltePreprocess;
|
|
1018
1053
|
} else {
|
|
1019
|
-
log.error(
|
|
1054
|
+
log.error(
|
|
1055
|
+
`ignoring plugin.sveltePreprocess of ${p.name} because it already defined plugin.api.sveltePreprocess.`
|
|
1056
|
+
);
|
|
1020
1057
|
}
|
|
1021
1058
|
});
|
|
1022
1059
|
}
|
|
@@ -1033,10 +1070,14 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1033
1070
|
}
|
|
1034
1071
|
}
|
|
1035
1072
|
if (ignored.length > 0) {
|
|
1036
|
-
log.debug(
|
|
1073
|
+
log.debug(
|
|
1074
|
+
`Ignoring svelte preprocessors defined by these vite plugins: ${ignored.map((p) => p.name).join(", ")}`
|
|
1075
|
+
);
|
|
1037
1076
|
}
|
|
1038
1077
|
if (included.length > 0) {
|
|
1039
|
-
log.debug(
|
|
1078
|
+
log.debug(
|
|
1079
|
+
`Adding svelte preprocessors defined by these vite plugins: ${included.map((p) => p.name).join(", ")}`
|
|
1080
|
+
);
|
|
1040
1081
|
appendPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess));
|
|
1041
1082
|
}
|
|
1042
1083
|
if (options.hot && options.emitCss) {
|
|
@@ -1072,24 +1113,32 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1072
1113
|
let invalidMap = false;
|
|
1073
1114
|
if (!result.map) {
|
|
1074
1115
|
invalidMap = true;
|
|
1075
|
-
log.warn.enabled && log.warn.once(
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1116
|
+
log.warn.enabled && log.warn.once(
|
|
1117
|
+
`preprocessor at index ${i} did not return a sourcemap for ${processorType} transform`,
|
|
1118
|
+
{
|
|
1119
|
+
filename: options.filename,
|
|
1120
|
+
type: processorType,
|
|
1121
|
+
processor: processorFn.toString()
|
|
1122
|
+
}
|
|
1123
|
+
);
|
|
1080
1124
|
} else if (((_a = result.map) == null ? void 0 : _a.mappings) === "") {
|
|
1081
1125
|
invalidMap = true;
|
|
1082
|
-
log.warn.enabled && log.warn.once(
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1126
|
+
log.warn.enabled && log.warn.once(
|
|
1127
|
+
`preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
|
|
1128
|
+
{
|
|
1129
|
+
filename: options.filename,
|
|
1130
|
+
type: processorType,
|
|
1131
|
+
processor: processorFn.toString()
|
|
1132
|
+
}
|
|
1133
|
+
);
|
|
1087
1134
|
}
|
|
1088
1135
|
if (invalidMap) {
|
|
1089
1136
|
try {
|
|
1090
1137
|
const map = await buildSourceMap(options.content, result.code, options.filename);
|
|
1091
1138
|
if (map) {
|
|
1092
|
-
log.debug.enabled && log.debug(
|
|
1139
|
+
log.debug.enabled && log.debug(
|
|
1140
|
+
`adding generated sourcemap to preprocesor result for ${options.filename}`
|
|
1141
|
+
);
|
|
1093
1142
|
result.map = map;
|
|
1094
1143
|
}
|
|
1095
1144
|
} catch (e) {
|
|
@@ -1122,7 +1171,9 @@ var allowedInlineOptions = /* @__PURE__ */ new Set([
|
|
|
1122
1171
|
...knownRootOptions
|
|
1123
1172
|
]);
|
|
1124
1173
|
function validateInlineOptions(inlineOptions) {
|
|
1125
|
-
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
1174
|
+
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
1175
|
+
(key) => !allowedInlineOptions.has(key)
|
|
1176
|
+
);
|
|
1126
1177
|
if (invalidKeys.length) {
|
|
1127
1178
|
log.warn(`invalid plugin options "${invalidKeys.join(", ")}" in inline config`, inlineOptions);
|
|
1128
1179
|
}
|
|
@@ -1133,7 +1184,11 @@ function convertPluginOptions(config) {
|
|
|
1133
1184
|
}
|
|
1134
1185
|
const invalidRootOptions = Object.keys(config).filter((key) => allowedPluginOptions.has(key));
|
|
1135
1186
|
if (invalidRootOptions.length > 0) {
|
|
1136
|
-
throw new Error(
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
`Invalid options in svelte config. Move the following options into 'vitePlugin:{...}': ${invalidRootOptions.join(
|
|
1189
|
+
", "
|
|
1190
|
+
)}`
|
|
1191
|
+
);
|
|
1137
1192
|
}
|
|
1138
1193
|
if (!config.vitePlugin) {
|
|
1139
1194
|
return config;
|
|
@@ -1142,15 +1197,29 @@ function convertPluginOptions(config) {
|
|
|
1142
1197
|
const pluginOptionKeys = Object.keys(pluginOptions);
|
|
1143
1198
|
const rootOptionsInPluginOptions = pluginOptionKeys.filter((key) => knownRootOptions.has(key));
|
|
1144
1199
|
if (rootOptionsInPluginOptions.length > 0) {
|
|
1145
|
-
throw new Error(
|
|
1146
|
-
|
|
1147
|
-
|
|
1200
|
+
throw new Error(
|
|
1201
|
+
`Invalid options in svelte config under vitePlugin:{...}', move them to the config root : ${rootOptionsInPluginOptions.join(
|
|
1202
|
+
", "
|
|
1203
|
+
)}`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
const duplicateOptions = pluginOptionKeys.filter(
|
|
1207
|
+
(key) => Object.prototype.hasOwnProperty.call(config, key)
|
|
1208
|
+
);
|
|
1148
1209
|
if (duplicateOptions.length > 0) {
|
|
1149
|
-
throw new Error(
|
|
1210
|
+
throw new Error(
|
|
1211
|
+
`Invalid duplicate options in svelte config under vitePlugin:{...}', they are defined in root too and must only exist once: ${duplicateOptions.join(
|
|
1212
|
+
", "
|
|
1213
|
+
)}`
|
|
1214
|
+
);
|
|
1150
1215
|
}
|
|
1151
1216
|
const unknownPluginOptions = pluginOptionKeys.filter((key) => !allowedPluginOptions.has(key));
|
|
1152
1217
|
if (unknownPluginOptions.length > 0) {
|
|
1153
|
-
log.warn(
|
|
1218
|
+
log.warn(
|
|
1219
|
+
`ignoring unknown plugin options in svelte config under vitePlugin:{...}: ${unknownPluginOptions.join(
|
|
1220
|
+
", "
|
|
1221
|
+
)}`
|
|
1222
|
+
);
|
|
1154
1223
|
unknownPluginOptions.forEach((unkownOption) => {
|
|
1155
1224
|
delete pluginOptions[unkownOption];
|
|
1156
1225
|
});
|
|
@@ -1171,14 +1240,21 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1171
1240
|
extensions: [".svelte"],
|
|
1172
1241
|
emitCss: true
|
|
1173
1242
|
};
|
|
1174
|
-
const svelteConfig = convertPluginOptions(
|
|
1243
|
+
const svelteConfig = convertPluginOptions(
|
|
1244
|
+
await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions)
|
|
1245
|
+
);
|
|
1175
1246
|
const extraOptions = {
|
|
1176
1247
|
root: viteConfigWithResolvedRoot.root,
|
|
1177
1248
|
isBuild: viteEnv.command === "build",
|
|
1178
1249
|
isServe: viteEnv.command === "serve",
|
|
1179
1250
|
isDebug: process.env.DEBUG != null
|
|
1180
1251
|
};
|
|
1181
|
-
const merged = mergeConfigs(
|
|
1252
|
+
const merged = mergeConfigs(
|
|
1253
|
+
defaultOptions,
|
|
1254
|
+
svelteConfig,
|
|
1255
|
+
inlineOptions,
|
|
1256
|
+
extraOptions
|
|
1257
|
+
);
|
|
1182
1258
|
if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
|
|
1183
1259
|
merged.configFile = svelteConfig.configFile;
|
|
1184
1260
|
}
|
|
@@ -1225,12 +1301,16 @@ function enforceOptionsForHmr(options) {
|
|
|
1225
1301
|
options.hot.injectCss = false;
|
|
1226
1302
|
}
|
|
1227
1303
|
if (options.compilerOptions.css) {
|
|
1228
|
-
log.warn(
|
|
1304
|
+
log.warn(
|
|
1305
|
+
"hmr and emitCss are enabled but compilerOptions.css is true, forcing it to false"
|
|
1306
|
+
);
|
|
1229
1307
|
options.compilerOptions.css = false;
|
|
1230
1308
|
}
|
|
1231
1309
|
} else {
|
|
1232
1310
|
if (options.hot === true || !options.hot.injectCss) {
|
|
1233
|
-
log.warn(
|
|
1311
|
+
log.warn(
|
|
1312
|
+
"hmr with emitCss disabled requires option hot.injectCss to be enabled, forcing it to true"
|
|
1313
|
+
);
|
|
1234
1314
|
if (options.hot === true) {
|
|
1235
1315
|
options.hot = { injectCss: true };
|
|
1236
1316
|
} else {
|
|
@@ -1238,7 +1318,9 @@ function enforceOptionsForHmr(options) {
|
|
|
1238
1318
|
}
|
|
1239
1319
|
}
|
|
1240
1320
|
if (!options.compilerOptions.css) {
|
|
1241
|
-
log.warn(
|
|
1321
|
+
log.warn(
|
|
1322
|
+
"hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to true"
|
|
1323
|
+
);
|
|
1242
1324
|
options.compilerOptions.css = true;
|
|
1243
1325
|
}
|
|
1244
1326
|
}
|
|
@@ -1251,7 +1333,9 @@ function enforceOptionsForProduction(options) {
|
|
|
1251
1333
|
options.hot = false;
|
|
1252
1334
|
}
|
|
1253
1335
|
if (options.compilerOptions.dev) {
|
|
1254
|
-
log.warn(
|
|
1336
|
+
log.warn(
|
|
1337
|
+
"you are building for production but compilerOptions.dev is true, forcing it to false"
|
|
1338
|
+
);
|
|
1255
1339
|
options.compilerOptions.dev = false;
|
|
1256
1340
|
}
|
|
1257
1341
|
}
|
|
@@ -1264,7 +1348,11 @@ function removeIgnoredOptions(options) {
|
|
|
1264
1348
|
const passedCompilerOptions = Object.keys(options.compilerOptions || {});
|
|
1265
1349
|
const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
|
|
1266
1350
|
if (passedIgnored.length) {
|
|
1267
|
-
log.warn(
|
|
1351
|
+
log.warn(
|
|
1352
|
+
`The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality. User-specified values are ignored. Please remove them from your configuration: ${passedIgnored.join(
|
|
1353
|
+
", "
|
|
1354
|
+
)}`
|
|
1355
|
+
);
|
|
1268
1356
|
passedIgnored.forEach((ignored) => {
|
|
1269
1357
|
delete options.compilerOptions[ignored];
|
|
1270
1358
|
});
|
|
@@ -1276,7 +1364,9 @@ function addSvelteKitOptions(options) {
|
|
|
1276
1364
|
const kit_browser_hydrate = (_a = options.kit.browser) == null ? void 0 : _a.hydrate;
|
|
1277
1365
|
const hydratable = kit_browser_hydrate !== false;
|
|
1278
1366
|
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1279
|
-
log.warn(
|
|
1367
|
+
log.warn(
|
|
1368
|
+
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${kit_browser_hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`
|
|
1369
|
+
);
|
|
1280
1370
|
}
|
|
1281
1371
|
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
|
|
1282
1372
|
options.compilerOptions.hydratable = hydratable;
|
|
@@ -1294,7 +1384,11 @@ function buildExtraViteConfig(options, config) {
|
|
|
1294
1384
|
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
|
|
1295
1385
|
}
|
|
1296
1386
|
};
|
|
1297
|
-
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
|
|
1387
|
+
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
|
|
1388
|
+
svelteDeps,
|
|
1389
|
+
options,
|
|
1390
|
+
config.optimizeDeps
|
|
1391
|
+
);
|
|
1298
1392
|
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1299
1393
|
extraViteConfig.optimizeDeps = {
|
|
1300
1394
|
...extraViteConfig.optimizeDeps,
|
|
@@ -1322,7 +1416,9 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1322
1416
|
};
|
|
1323
1417
|
if (!isExcluded("svelte")) {
|
|
1324
1418
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
1325
|
-
log.debug(
|
|
1419
|
+
log.debug(
|
|
1420
|
+
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(", ")} `
|
|
1421
|
+
);
|
|
1326
1422
|
include.push(...svelteImportsToInclude.filter((x) => !isIncluded(x)));
|
|
1327
1423
|
} else {
|
|
1328
1424
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
@@ -1331,7 +1427,9 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1331
1427
|
return { include, exclude };
|
|
1332
1428
|
}
|
|
1333
1429
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
1334
|
-
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
|
|
1430
|
+
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
|
|
1431
|
+
(dep) => !isIncluded(dep)
|
|
1432
|
+
);
|
|
1335
1433
|
log.debug(`automatically excluding found svelte dependencies: ${svelteDepsToExclude.join(", ")}`);
|
|
1336
1434
|
exclude.push(...svelteDepsToExclude.filter((x) => !isExcluded(x)));
|
|
1337
1435
|
if (options.disableDependencyReinclusion !== true) {
|
|
@@ -1343,7 +1441,10 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1343
1441
|
const localRequire = (0, import_module3.createRequire)(`${dep.dir}/package.json`);
|
|
1344
1442
|
return Object.keys(dep.pkg.dependencies || {}).filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire)).map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(" > "));
|
|
1345
1443
|
});
|
|
1346
|
-
log.debug(
|
|
1444
|
+
log.debug(
|
|
1445
|
+
`reincluding transitive dependencies of excluded svelte dependencies`,
|
|
1446
|
+
transitiveDepsToInclude
|
|
1447
|
+
);
|
|
1347
1448
|
include.push(...transitiveDepsToInclude);
|
|
1348
1449
|
}
|
|
1349
1450
|
return { include, exclude };
|
|
@@ -1354,25 +1455,35 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1354
1455
|
if (!((_b = (_a = config.ssr) == null ? void 0 : _a.external) == null ? void 0 : _b.includes("svelte"))) {
|
|
1355
1456
|
noExternal.push("svelte", /^svelte\//);
|
|
1356
1457
|
}
|
|
1357
|
-
noExternal.push(
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1458
|
+
noExternal.push(
|
|
1459
|
+
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
|
|
1460
|
+
(x) => {
|
|
1461
|
+
var _a2, _b2;
|
|
1462
|
+
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
|
|
1463
|
+
}
|
|
1464
|
+
)
|
|
1465
|
+
);
|
|
1361
1466
|
const ssr = {
|
|
1362
1467
|
noExternal,
|
|
1363
1468
|
external: []
|
|
1364
1469
|
};
|
|
1365
1470
|
if (options.isServe) {
|
|
1366
|
-
ssr.external = Array.from(
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1471
|
+
ssr.external = Array.from(
|
|
1472
|
+
new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
|
|
1473
|
+
).filter(
|
|
1474
|
+
(dep) => {
|
|
1475
|
+
var _a2, _b2;
|
|
1476
|
+
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
|
|
1477
|
+
}
|
|
1478
|
+
);
|
|
1370
1479
|
}
|
|
1371
1480
|
return ssr;
|
|
1372
1481
|
}
|
|
1373
1482
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1374
1483
|
var _a, _b;
|
|
1375
|
-
const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
|
|
1484
|
+
const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
|
|
1485
|
+
(plugin) => plugin.name === facadeEsbuildSveltePluginName
|
|
1486
|
+
);
|
|
1376
1487
|
if (facadeEsbuildSveltePlugin) {
|
|
1377
1488
|
Object.assign(facadeEsbuildSveltePlugin, esbuildSveltePlugin(options));
|
|
1378
1489
|
}
|
|
@@ -1473,7 +1584,10 @@ var VitePluginSvelteCache = class {
|
|
|
1473
1584
|
return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
|
|
1474
1585
|
}
|
|
1475
1586
|
setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
|
|
1476
|
-
this._resolvedSvelteFields.set(
|
|
1587
|
+
this._resolvedSvelteFields.set(
|
|
1588
|
+
this._getResolvedSvelteFieldKey(importee, importer),
|
|
1589
|
+
resolvedSvelte
|
|
1590
|
+
);
|
|
1477
1591
|
}
|
|
1478
1592
|
_getResolvedSvelteFieldKey(importee, importer) {
|
|
1479
1593
|
return importer ? `${importer} > ${importee}` : importee;
|
|
@@ -1494,7 +1608,9 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1494
1608
|
const dependants = cache.getDependants(filename);
|
|
1495
1609
|
dependants.forEach((dependant) => {
|
|
1496
1610
|
if (import_fs4.default.existsSync(dependant)) {
|
|
1497
|
-
log.debug(
|
|
1611
|
+
log.debug(
|
|
1612
|
+
`emitting virtual change event for "${dependant}" because depdendency "${filename}" changed`
|
|
1613
|
+
);
|
|
1498
1614
|
watcher.emit("change", dependant);
|
|
1499
1615
|
}
|
|
1500
1616
|
});
|
|
@@ -1671,7 +1787,7 @@ function svelteInspector() {
|
|
|
1671
1787
|
} else {
|
|
1672
1788
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1673
1789
|
const out_dir = import_path8.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
|
|
1674
|
-
inspectorOptions.appendTo = `${out_dir}/
|
|
1790
|
+
inspectorOptions.appendTo = `${out_dir}/generated/root.svelte`;
|
|
1675
1791
|
}
|
|
1676
1792
|
appendTo = inspectorOptions.appendTo;
|
|
1677
1793
|
}
|
|
@@ -1810,24 +1926,35 @@ function svelte(inlineOptions) {
|
|
|
1810
1926
|
}
|
|
1811
1927
|
if (ssr && importee === "svelte") {
|
|
1812
1928
|
if (!resolvedSvelteSSR) {
|
|
1813
|
-
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1929
|
+
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
|
|
1930
|
+
(svelteSSR) => {
|
|
1931
|
+
log.debug("resolved svelte to svelte/ssr");
|
|
1932
|
+
return svelteSSR;
|
|
1933
|
+
},
|
|
1934
|
+
(err) => {
|
|
1935
|
+
log.debug(
|
|
1936
|
+
"failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it",
|
|
1937
|
+
err
|
|
1938
|
+
);
|
|
1939
|
+
return null;
|
|
1940
|
+
}
|
|
1941
|
+
);
|
|
1820
1942
|
}
|
|
1821
1943
|
return resolvedSvelteSSR;
|
|
1822
1944
|
}
|
|
1823
1945
|
try {
|
|
1824
1946
|
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
1825
1947
|
if (resolved) {
|
|
1826
|
-
log.debug(
|
|
1948
|
+
log.debug(
|
|
1949
|
+
`resolveId resolved ${resolved} via package.json svelte field of ${importee}`
|
|
1950
|
+
);
|
|
1827
1951
|
return resolved;
|
|
1828
1952
|
}
|
|
1829
1953
|
} catch (e) {
|
|
1830
|
-
log.debug.once(
|
|
1954
|
+
log.debug.once(
|
|
1955
|
+
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
|
|
1956
|
+
e
|
|
1957
|
+
);
|
|
1831
1958
|
}
|
|
1832
1959
|
},
|
|
1833
1960
|
async transform(code, id, opts) {
|