@sveltejs/vite-plugin-svelte 1.2.0 → 1.3.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/dist/index.cjs +452 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +444 -201
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +4 -1
- package/src/utils/compile.ts +36 -3
- package/src/utils/constants.ts +2 -0
- package/src/utils/esbuild.ts +19 -7
- package/src/utils/options.ts +90 -13
- package/src/utils/vite-plugin-svelte-stats.ts +206 -0
package/dist/index.cjs
CHANGED
|
@@ -36,8 +36,8 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" +
|
|
|
36
36
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
37
37
|
|
|
38
38
|
// src/index.ts
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_fs7 = __toESM(require("fs"), 1);
|
|
40
|
+
var import_vitefu4 = require("vitefu");
|
|
41
41
|
|
|
42
42
|
// src/utils/log.ts
|
|
43
43
|
var import_colors = require("kleur/colors");
|
|
@@ -318,81 +318,105 @@ function toSafe(base64) {
|
|
|
318
318
|
|
|
319
319
|
// src/utils/compile.ts
|
|
320
320
|
var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
321
|
-
var _createCompileSvelte = (makeHot) =>
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
321
|
+
var _createCompileSvelte = (makeHot) => {
|
|
322
|
+
let stats;
|
|
323
|
+
return async function compileSvelte2(svelteRequest, code, options) {
|
|
324
|
+
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
|
|
325
|
+
const { emitCss = true } = options;
|
|
326
|
+
const dependencies = [];
|
|
327
|
+
if (options.stats) {
|
|
328
|
+
if (options.isBuild) {
|
|
329
|
+
if (!stats) {
|
|
330
|
+
stats = options.stats.startCollection(`${ssr ? "ssr" : "dom"} compile`, {
|
|
331
|
+
logInProgress: () => false
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
if (ssr && !stats) {
|
|
336
|
+
stats = options.stats.startCollection("ssr compile");
|
|
337
|
+
}
|
|
338
|
+
if (!ssr && stats) {
|
|
339
|
+
stats.finish();
|
|
340
|
+
stats = void 0;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
341
343
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
344
|
+
const compileOptions = {
|
|
345
|
+
...options.compilerOptions,
|
|
346
|
+
filename,
|
|
347
|
+
generate: ssr ? "ssr" : "dom",
|
|
348
|
+
format: "esm"
|
|
349
|
+
};
|
|
350
|
+
if (options.hot && options.emitCss) {
|
|
351
|
+
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
|
352
|
+
log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
|
|
353
|
+
compileOptions.cssHash = () => hash;
|
|
350
354
|
}
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
355
|
+
if (ssr && compileOptions.enableSourcemap !== false) {
|
|
356
|
+
if (typeof compileOptions.enableSourcemap === "object") {
|
|
357
|
+
compileOptions.enableSourcemap.css = false;
|
|
358
|
+
} else {
|
|
359
|
+
compileOptions.enableSourcemap = { js: true, css: false };
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
let preprocessed;
|
|
363
|
+
if (options.preprocess) {
|
|
364
|
+
try {
|
|
365
|
+
preprocessed = await (0, import_compiler.preprocess)(code, options.preprocess, { filename });
|
|
366
|
+
} catch (e) {
|
|
367
|
+
e.message = `Error while preprocessing ${filename}${e.message ? ` - ${e.message}` : ""}`;
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
370
|
+
if (preprocessed.dependencies)
|
|
371
|
+
dependencies.push(...preprocessed.dependencies);
|
|
372
|
+
if (preprocessed.map)
|
|
373
|
+
compileOptions.sourcemap = preprocessed.map;
|
|
374
|
+
}
|
|
375
|
+
const finalCode = preprocessed ? preprocessed.code : code;
|
|
376
|
+
const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
|
|
377
|
+
filename,
|
|
378
|
+
code: finalCode,
|
|
379
|
+
compileOptions
|
|
380
|
+
});
|
|
381
|
+
if (dynamicCompileOptions && log.debug.enabled) {
|
|
382
|
+
log.debug(
|
|
383
|
+
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
const finalCompileOptions = dynamicCompileOptions ? {
|
|
387
|
+
...compileOptions,
|
|
388
|
+
...dynamicCompileOptions
|
|
389
|
+
} : compileOptions;
|
|
390
|
+
const endStat = stats?.start(filename);
|
|
391
|
+
const compiled = (0, import_compiler.compile)(finalCode, finalCompileOptions);
|
|
392
|
+
if (endStat) {
|
|
393
|
+
endStat();
|
|
394
|
+
}
|
|
395
|
+
const hasCss = compiled.css?.code?.trim().length > 0;
|
|
396
|
+
if (emitCss && hasCss) {
|
|
397
|
+
compiled.js.code += `
|
|
375
398
|
import ${JSON.stringify(cssId)};
|
|
376
399
|
`;
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
400
|
+
}
|
|
401
|
+
if (!ssr && makeHot) {
|
|
402
|
+
compiled.js.code = makeHot({
|
|
403
|
+
id: filename,
|
|
404
|
+
compiledCode: compiled.js.code,
|
|
405
|
+
hotOptions: { ...options.hot, injectCss: options.hot?.injectCss === true && hasCss },
|
|
406
|
+
compiled,
|
|
407
|
+
originalCode: code,
|
|
408
|
+
compileOptions: finalCompileOptions
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
compiled.js.dependencies = dependencies;
|
|
412
|
+
return {
|
|
413
|
+
filename,
|
|
414
|
+
normalizedFilename,
|
|
415
|
+
lang: code.match(scriptLangRE)?.[1] || "js",
|
|
383
416
|
compiled,
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
compiled.js.dependencies = dependencies;
|
|
389
|
-
return {
|
|
390
|
-
filename,
|
|
391
|
-
normalizedFilename,
|
|
392
|
-
lang: code.match(scriptLangRE)?.[1] || "js",
|
|
393
|
-
compiled,
|
|
394
|
-
ssr,
|
|
395
|
-
dependencies
|
|
417
|
+
ssr,
|
|
418
|
+
dependencies
|
|
419
|
+
};
|
|
396
420
|
};
|
|
397
421
|
};
|
|
398
422
|
function buildMakeHot(options) {
|
|
@@ -600,6 +624,7 @@ var SVELTE_HMR_IMPORTS = [
|
|
|
600
624
|
"svelte-hmr/runtime/proxy-adapter-dom.js",
|
|
601
625
|
"svelte-hmr"
|
|
602
626
|
];
|
|
627
|
+
var SVELTE_EXPORT_CONDITIONS = ["svelte"];
|
|
603
628
|
|
|
604
629
|
// src/utils/options.ts
|
|
605
630
|
var import_path4 = __toESM(require("path"), 1);
|
|
@@ -702,19 +727,28 @@ function esbuildSveltePlugin(options) {
|
|
|
702
727
|
return;
|
|
703
728
|
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
|
|
704
729
|
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
|
|
730
|
+
let statsCollection;
|
|
731
|
+
build.onStart(() => {
|
|
732
|
+
statsCollection = options.stats?.startCollection("prebundle libraries", {
|
|
733
|
+
logResult: (c) => c.stats.length > 1
|
|
734
|
+
});
|
|
735
|
+
});
|
|
705
736
|
build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => {
|
|
706
|
-
const code =
|
|
737
|
+
const code = (0, import_fs2.readFileSync)(filename, "utf8");
|
|
707
738
|
try {
|
|
708
|
-
const contents = await compileSvelte(options, { filename, code });
|
|
739
|
+
const contents = await compileSvelte(options, { filename, code }, statsCollection);
|
|
709
740
|
return { contents };
|
|
710
741
|
} catch (e) {
|
|
711
742
|
return { errors: [toESBuildError(e, options)] };
|
|
712
743
|
}
|
|
713
744
|
});
|
|
745
|
+
build.onEnd(() => {
|
|
746
|
+
statsCollection?.finish();
|
|
747
|
+
});
|
|
714
748
|
}
|
|
715
749
|
};
|
|
716
750
|
}
|
|
717
|
-
async function compileSvelte(options, { filename, code }) {
|
|
751
|
+
async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
718
752
|
let css = options.compilerOptions.css;
|
|
719
753
|
if (css !== "none") {
|
|
720
754
|
css = isCssString ? "injected" : true;
|
|
@@ -750,7 +784,11 @@ async function compileSvelte(options, { filename, code }) {
|
|
|
750
784
|
...compileOptions,
|
|
751
785
|
...dynamicCompileOptions
|
|
752
786
|
} : compileOptions;
|
|
787
|
+
const endStat = statsCollection?.start(filename);
|
|
753
788
|
const compiled = (0, import_compiler3.compile)(finalCode, finalCompileOptions);
|
|
789
|
+
if (endStat) {
|
|
790
|
+
endStat();
|
|
791
|
+
}
|
|
754
792
|
return compiled.js.code + "//# sourceMappingURL=" + compiled.js.map.toUrl();
|
|
755
793
|
}
|
|
756
794
|
|
|
@@ -1012,7 +1050,7 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1012
1050
|
|
|
1013
1051
|
// src/utils/options.ts
|
|
1014
1052
|
var import_deepmerge = __toESM(require("deepmerge"), 1);
|
|
1015
|
-
var
|
|
1053
|
+
var import_vitefu3 = require("vitefu");
|
|
1016
1054
|
|
|
1017
1055
|
// src/utils/dependencies.ts
|
|
1018
1056
|
var import_path3 = __toESM(require("path"), 1);
|
|
@@ -1076,6 +1114,159 @@ function isCommonDepWithoutSvelteField(dependency) {
|
|
|
1076
1114
|
);
|
|
1077
1115
|
}
|
|
1078
1116
|
|
|
1117
|
+
// src/utils/vite-plugin-svelte-stats.ts
|
|
1118
|
+
var import_vitefu2 = require("vitefu");
|
|
1119
|
+
var import_fs3 = require("fs");
|
|
1120
|
+
var import_perf_hooks = require("perf_hooks");
|
|
1121
|
+
var defaultCollectionOptions = {
|
|
1122
|
+
logInProgress: (c, now) => now - c.collectionStart > 500 && c.stats.length > 1,
|
|
1123
|
+
logResult: () => true
|
|
1124
|
+
};
|
|
1125
|
+
function humanDuration(n) {
|
|
1126
|
+
return n < 100 ? `${n.toFixed(1)}ms` : `${(n / 1e3).toFixed(2)}s`;
|
|
1127
|
+
}
|
|
1128
|
+
function formatPackageStats(pkgStats) {
|
|
1129
|
+
const statLines = pkgStats.map((pkgStat) => {
|
|
1130
|
+
const duration = pkgStat.duration;
|
|
1131
|
+
const avg = duration / pkgStat.files;
|
|
1132
|
+
return [pkgStat.pkg, `${pkgStat.files}`, humanDuration(duration), humanDuration(avg)];
|
|
1133
|
+
});
|
|
1134
|
+
statLines.unshift(["package", "files", "time", "avg"]);
|
|
1135
|
+
const columnWidths = statLines.reduce(
|
|
1136
|
+
(widths, row) => {
|
|
1137
|
+
for (let i = 0; i < row.length; i++) {
|
|
1138
|
+
const cell = row[i];
|
|
1139
|
+
if (widths[i] < cell.length) {
|
|
1140
|
+
widths[i] = cell.length;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return widths;
|
|
1144
|
+
},
|
|
1145
|
+
statLines[0].map(() => 0)
|
|
1146
|
+
);
|
|
1147
|
+
const table = statLines.map(
|
|
1148
|
+
(row) => row.map((cell, i) => {
|
|
1149
|
+
if (i === 0) {
|
|
1150
|
+
return cell.padEnd(columnWidths[i], " ");
|
|
1151
|
+
} else {
|
|
1152
|
+
return cell.padStart(columnWidths[i], " ");
|
|
1153
|
+
}
|
|
1154
|
+
}).join(" ")
|
|
1155
|
+
).join("\n");
|
|
1156
|
+
return table;
|
|
1157
|
+
}
|
|
1158
|
+
var VitePluginSvelteStats = class {
|
|
1159
|
+
constructor() {
|
|
1160
|
+
this._packages = [];
|
|
1161
|
+
this._collections = [];
|
|
1162
|
+
}
|
|
1163
|
+
startCollection(name, opts) {
|
|
1164
|
+
const options = {
|
|
1165
|
+
...defaultCollectionOptions,
|
|
1166
|
+
...opts
|
|
1167
|
+
};
|
|
1168
|
+
const stats = [];
|
|
1169
|
+
const collectionStart = import_perf_hooks.performance.now();
|
|
1170
|
+
const _this = this;
|
|
1171
|
+
let hasLoggedProgress = false;
|
|
1172
|
+
const collection = {
|
|
1173
|
+
name,
|
|
1174
|
+
options,
|
|
1175
|
+
stats,
|
|
1176
|
+
collectionStart,
|
|
1177
|
+
finished: false,
|
|
1178
|
+
start(file) {
|
|
1179
|
+
if (collection.finished) {
|
|
1180
|
+
throw new Error("called after finish() has been used");
|
|
1181
|
+
}
|
|
1182
|
+
const start = import_perf_hooks.performance.now();
|
|
1183
|
+
const stat = { file, start, end: start };
|
|
1184
|
+
return () => {
|
|
1185
|
+
const now = import_perf_hooks.performance.now();
|
|
1186
|
+
stat.end = now;
|
|
1187
|
+
stats.push(stat);
|
|
1188
|
+
if (!hasLoggedProgress && options.logInProgress(collection, now)) {
|
|
1189
|
+
hasLoggedProgress = true;
|
|
1190
|
+
log.info(`${name} in progress ...`);
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
},
|
|
1194
|
+
async finish() {
|
|
1195
|
+
await _this._finish(collection);
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
_this._collections.push(collection);
|
|
1199
|
+
return collection;
|
|
1200
|
+
}
|
|
1201
|
+
async finishAll() {
|
|
1202
|
+
await Promise.all(this._collections.map((c) => c.finish()));
|
|
1203
|
+
}
|
|
1204
|
+
async _finish(collection) {
|
|
1205
|
+
collection.finished = true;
|
|
1206
|
+
const now = import_perf_hooks.performance.now();
|
|
1207
|
+
collection.duration = now - collection.collectionStart;
|
|
1208
|
+
const logResult = collection.options.logResult(collection);
|
|
1209
|
+
if (logResult) {
|
|
1210
|
+
await this._aggregateStatsResult(collection);
|
|
1211
|
+
log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
|
|
1212
|
+
}
|
|
1213
|
+
const index = this._collections.indexOf(collection);
|
|
1214
|
+
this._collections.splice(index, 1);
|
|
1215
|
+
collection.stats.length = 0;
|
|
1216
|
+
collection.stats = [];
|
|
1217
|
+
if (collection.packageStats) {
|
|
1218
|
+
collection.packageStats.length = 0;
|
|
1219
|
+
collection.packageStats = [];
|
|
1220
|
+
}
|
|
1221
|
+
collection.start = () => () => {
|
|
1222
|
+
};
|
|
1223
|
+
collection.finish = () => {
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
async _aggregateStatsResult(collection) {
|
|
1227
|
+
const stats = collection.stats;
|
|
1228
|
+
for (const stat of stats) {
|
|
1229
|
+
let pkg = this._packages.find((p) => stat.file.startsWith(p.path));
|
|
1230
|
+
if (!pkg) {
|
|
1231
|
+
let pkgPath = await (0, import_vitefu2.findClosestPkgJsonPath)(stat.file);
|
|
1232
|
+
if (pkgPath) {
|
|
1233
|
+
let path9 = pkgPath?.replace(/package.json$/, "");
|
|
1234
|
+
let name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
|
|
1235
|
+
if (!name) {
|
|
1236
|
+
pkgPath = await (0, import_vitefu2.findClosestPkgJsonPath)(path9);
|
|
1237
|
+
if (pkgPath) {
|
|
1238
|
+
path9 = pkgPath?.replace(/package.json$/, "");
|
|
1239
|
+
name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (path9 && name) {
|
|
1243
|
+
pkg = { path: path9, name };
|
|
1244
|
+
this._packages.push(pkg);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
stat.pkg = pkg?.name ?? "$unknown";
|
|
1249
|
+
}
|
|
1250
|
+
const grouped = {};
|
|
1251
|
+
stats.forEach((stat) => {
|
|
1252
|
+
const pkg = stat.pkg;
|
|
1253
|
+
let group = grouped[pkg];
|
|
1254
|
+
if (!group) {
|
|
1255
|
+
group = grouped[pkg] = {
|
|
1256
|
+
files: 0,
|
|
1257
|
+
duration: 0,
|
|
1258
|
+
pkg
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
group.files += 1;
|
|
1262
|
+
group.duration += stat.end - stat.start;
|
|
1263
|
+
});
|
|
1264
|
+
const groups = Object.values(grouped);
|
|
1265
|
+
groups.sort((a, b) => b.duration - a.duration);
|
|
1266
|
+
collection.packageStats = groups;
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1079
1270
|
// src/utils/options.ts
|
|
1080
1271
|
var cssAsString = atLeastSvelte("3.53.0");
|
|
1081
1272
|
var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
@@ -1161,16 +1352,18 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1161
1352
|
...viteUserConfig,
|
|
1162
1353
|
root: resolveViteRoot(viteUserConfig)
|
|
1163
1354
|
};
|
|
1355
|
+
const isBuild = viteEnv.command === "build";
|
|
1164
1356
|
const defaultOptions = {
|
|
1165
1357
|
extensions: [".svelte"],
|
|
1166
|
-
emitCss: true
|
|
1358
|
+
emitCss: true,
|
|
1359
|
+
prebundleSvelteLibraries: !isBuild
|
|
1167
1360
|
};
|
|
1168
1361
|
const svelteConfig = convertPluginOptions(
|
|
1169
1362
|
await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions)
|
|
1170
1363
|
);
|
|
1171
1364
|
const extraOptions = {
|
|
1172
1365
|
root: viteConfigWithResolvedRoot.root,
|
|
1173
|
-
isBuild
|
|
1366
|
+
isBuild,
|
|
1174
1367
|
isServe: viteEnv.command === "serve",
|
|
1175
1368
|
isDebug: process.env.DEBUG != null
|
|
1176
1369
|
};
|
|
@@ -1217,6 +1410,12 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1217
1410
|
addExtraPreprocessors(merged, viteConfig);
|
|
1218
1411
|
enforceOptionsForHmr(merged);
|
|
1219
1412
|
enforceOptionsForProduction(merged);
|
|
1413
|
+
const isLogLevelInfo = [void 0, "info"].includes(viteConfig.logLevel);
|
|
1414
|
+
const disableCompileStats = merged.experimental?.disableCompileStats;
|
|
1415
|
+
const statsEnabled = disableCompileStats !== true && disableCompileStats !== (merged.isBuild ? "build" : "dev");
|
|
1416
|
+
if (statsEnabled && isLogLevelInfo) {
|
|
1417
|
+
merged.stats = new VitePluginSvelteStats();
|
|
1418
|
+
}
|
|
1220
1419
|
return merged;
|
|
1221
1420
|
}
|
|
1222
1421
|
function enforceOptionsForHmr(options) {
|
|
@@ -1313,7 +1512,8 @@ async function buildExtraViteConfig(options, config) {
|
|
|
1313
1512
|
const extraViteConfig = {
|
|
1314
1513
|
resolve: {
|
|
1315
1514
|
mainFields: [...SVELTE_RESOLVE_MAIN_FIELDS],
|
|
1316
|
-
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
|
|
1515
|
+
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS],
|
|
1516
|
+
conditions: [...SVELTE_EXPORT_CONDITIONS]
|
|
1317
1517
|
}
|
|
1318
1518
|
};
|
|
1319
1519
|
const extraSvelteConfig = buildExtraConfigForSvelte(config);
|
|
@@ -1322,13 +1522,13 @@ async function buildExtraViteConfig(options, config) {
|
|
|
1322
1522
|
include: [
|
|
1323
1523
|
...extraSvelteConfig.optimizeDeps.include,
|
|
1324
1524
|
...extraDepsConfig.optimizeDeps.include.filter(
|
|
1325
|
-
(dep) => !(0,
|
|
1525
|
+
(dep) => !(0, import_vitefu3.isDepExcluded)(dep, extraSvelteConfig.optimizeDeps.exclude)
|
|
1326
1526
|
)
|
|
1327
1527
|
],
|
|
1328
1528
|
exclude: [
|
|
1329
1529
|
...extraSvelteConfig.optimizeDeps.exclude,
|
|
1330
1530
|
...extraDepsConfig.optimizeDeps.exclude.filter(
|
|
1331
|
-
(dep) => !(0,
|
|
1531
|
+
(dep) => !(0, import_vitefu3.isDepIncluded)(dep, extraSvelteConfig.optimizeDeps.include)
|
|
1332
1532
|
)
|
|
1333
1533
|
]
|
|
1334
1534
|
};
|
|
@@ -1336,36 +1536,76 @@ async function buildExtraViteConfig(options, config) {
|
|
|
1336
1536
|
external: [
|
|
1337
1537
|
...extraSvelteConfig.ssr.external,
|
|
1338
1538
|
...extraDepsConfig.ssr.external.filter(
|
|
1339
|
-
(dep) => !(0,
|
|
1539
|
+
(dep) => !(0, import_vitefu3.isDepNoExternaled)(dep, extraSvelteConfig.ssr.noExternal)
|
|
1340
1540
|
)
|
|
1341
1541
|
],
|
|
1342
1542
|
noExternal: [
|
|
1343
1543
|
...extraSvelteConfig.ssr.noExternal,
|
|
1344
1544
|
...extraDepsConfig.ssr.noExternal.filter(
|
|
1345
|
-
(dep) => !(0,
|
|
1545
|
+
(dep) => !(0, import_vitefu3.isDepExternaled)(dep, extraSvelteConfig.ssr.external)
|
|
1346
1546
|
)
|
|
1347
1547
|
]
|
|
1348
1548
|
};
|
|
1349
1549
|
if (options.prebundleSvelteLibraries) {
|
|
1350
|
-
extraViteConfig.optimizeDeps
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1550
|
+
extraViteConfig.optimizeDeps = {
|
|
1551
|
+
...extraViteConfig.optimizeDeps,
|
|
1552
|
+
extensions: options.extensions ?? [".svelte"],
|
|
1553
|
+
esbuildOptions: {
|
|
1554
|
+
plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {
|
|
1555
|
+
} }]
|
|
1556
|
+
}
|
|
1354
1557
|
};
|
|
1355
1558
|
}
|
|
1356
1559
|
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && config.experimental?.hmrPartialAccept !== false) {
|
|
1357
1560
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1358
1561
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1359
1562
|
}
|
|
1563
|
+
validateViteConfig(extraViteConfig, config, options);
|
|
1360
1564
|
return extraViteConfig;
|
|
1361
1565
|
}
|
|
1566
|
+
function validateViteConfig(extraViteConfig, config, options) {
|
|
1567
|
+
const { prebundleSvelteLibraries, isBuild } = options;
|
|
1568
|
+
if (prebundleSvelteLibraries) {
|
|
1569
|
+
const isEnabled = (option) => option !== true && option !== (isBuild ? "build" : "dev");
|
|
1570
|
+
const logWarning = (name, value, recommendation) => log.warn.once(
|
|
1571
|
+
`Incompatible options: \`prebundleSvelteLibraries: true\` and vite \`${name}: ${JSON.stringify(
|
|
1572
|
+
value
|
|
1573
|
+
)}\` ${isBuild ? "during build." : "."} ${recommendation}`
|
|
1574
|
+
);
|
|
1575
|
+
const viteOptimizeDepsDisabled = config.optimizeDeps?.disabled ?? "build";
|
|
1576
|
+
const isOptimizeDepsEnabled = isEnabled(viteOptimizeDepsDisabled);
|
|
1577
|
+
if (!isBuild && !isOptimizeDepsEnabled) {
|
|
1578
|
+
logWarning(
|
|
1579
|
+
"optimizeDeps.disabled",
|
|
1580
|
+
viteOptimizeDepsDisabled,
|
|
1581
|
+
'Forcing `optimizeDeps.disabled: "build"`. Disable prebundleSvelteLibraries or update your vite config to enable optimizeDeps during dev.'
|
|
1582
|
+
);
|
|
1583
|
+
extraViteConfig.optimizeDeps.disabled = "build";
|
|
1584
|
+
} else if (isBuild && isOptimizeDepsEnabled) {
|
|
1585
|
+
logWarning(
|
|
1586
|
+
"optimizeDeps.disabled",
|
|
1587
|
+
viteOptimizeDepsDisabled,
|
|
1588
|
+
"Disable optimizeDeps or prebundleSvelteLibraries for build if you experience errors."
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1362
1593
|
async function buildExtraConfigForDependencies(options, config) {
|
|
1363
|
-
const depsConfig = await (0,
|
|
1594
|
+
const depsConfig = await (0, import_vitefu3.crawlFrameworkPkgs)({
|
|
1364
1595
|
root: options.root,
|
|
1365
1596
|
isBuild: options.isBuild,
|
|
1366
1597
|
viteUserConfig: config,
|
|
1367
1598
|
isFrameworkPkgByJson(pkgJson) {
|
|
1368
|
-
|
|
1599
|
+
let hasSvelteCondition = false;
|
|
1600
|
+
if (typeof pkgJson.exports === "object") {
|
|
1601
|
+
JSON.stringify(pkgJson.exports, (key, value) => {
|
|
1602
|
+
if (SVELTE_EXPORT_CONDITIONS.includes(key)) {
|
|
1603
|
+
hasSvelteCondition = true;
|
|
1604
|
+
}
|
|
1605
|
+
return value;
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
return hasSvelteCondition || !!pkgJson.svelte;
|
|
1369
1609
|
},
|
|
1370
1610
|
isSemiFrameworkPkgByJson(pkgJson) {
|
|
1371
1611
|
return !!pkgJson.dependencies?.svelte || !!pkgJson.peerDependencies?.svelte;
|
|
@@ -1384,7 +1624,7 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
1384
1624
|
depsConfig.optimizeDeps.exclude = [];
|
|
1385
1625
|
const userExclude = config.optimizeDeps?.exclude;
|
|
1386
1626
|
depsConfig.optimizeDeps.include = !userExclude ? [] : depsConfig.optimizeDeps.include.filter((dep) => {
|
|
1387
|
-
return dep.includes(">") && dep.split(">").slice(0, -1).some((d) => (0,
|
|
1627
|
+
return dep.includes(">") && dep.split(">").slice(0, -1).some((d) => (0, import_vitefu3.isDepExcluded)(d.trim(), userExclude));
|
|
1388
1628
|
});
|
|
1389
1629
|
}
|
|
1390
1630
|
if (options.disableDependencyReinclusion === true) {
|
|
@@ -1406,7 +1646,7 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
1406
1646
|
function buildExtraConfigForSvelte(config) {
|
|
1407
1647
|
const include = [];
|
|
1408
1648
|
const exclude = ["svelte-hmr"];
|
|
1409
|
-
if (!(0,
|
|
1649
|
+
if (!(0, import_vitefu3.isDepExcluded)("svelte", config.optimizeDeps?.exclude ?? [])) {
|
|
1410
1650
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
1411
1651
|
log.debug(
|
|
1412
1652
|
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(", ")} `
|
|
@@ -1417,7 +1657,7 @@ function buildExtraConfigForSvelte(config) {
|
|
|
1417
1657
|
}
|
|
1418
1658
|
const noExternal = [];
|
|
1419
1659
|
const external = [];
|
|
1420
|
-
if (!(0,
|
|
1660
|
+
if (!(0, import_vitefu3.isDepExternaled)("svelte", config.ssr?.external ?? [])) {
|
|
1421
1661
|
noExternal.push("svelte", /^svelte\//);
|
|
1422
1662
|
}
|
|
1423
1663
|
return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
|
|
@@ -1431,113 +1671,8 @@ function patchResolvedViteConfig(viteConfig, options) {
|
|
|
1431
1671
|
}
|
|
1432
1672
|
}
|
|
1433
1673
|
|
|
1434
|
-
// src/utils/vite-plugin-svelte-cache.ts
|
|
1435
|
-
var VitePluginSvelteCache = class {
|
|
1436
|
-
constructor() {
|
|
1437
|
-
this._css = /* @__PURE__ */ new Map();
|
|
1438
|
-
this._js = /* @__PURE__ */ new Map();
|
|
1439
|
-
this._dependencies = /* @__PURE__ */ new Map();
|
|
1440
|
-
this._dependants = /* @__PURE__ */ new Map();
|
|
1441
|
-
this._resolvedSvelteFields = /* @__PURE__ */ new Map();
|
|
1442
|
-
this._errors = /* @__PURE__ */ new Map();
|
|
1443
|
-
}
|
|
1444
|
-
update(compileData) {
|
|
1445
|
-
this._errors.delete(compileData.normalizedFilename);
|
|
1446
|
-
this.updateCSS(compileData);
|
|
1447
|
-
this.updateJS(compileData);
|
|
1448
|
-
this.updateDependencies(compileData);
|
|
1449
|
-
}
|
|
1450
|
-
has(svelteRequest) {
|
|
1451
|
-
const id = svelteRequest.normalizedFilename;
|
|
1452
|
-
return this._errors.has(id) || this._js.has(id) || this._css.has(id);
|
|
1453
|
-
}
|
|
1454
|
-
setError(svelteRequest, error) {
|
|
1455
|
-
this.remove(svelteRequest, true);
|
|
1456
|
-
this._errors.set(svelteRequest.normalizedFilename, error);
|
|
1457
|
-
}
|
|
1458
|
-
updateCSS(compileData) {
|
|
1459
|
-
this._css.set(compileData.normalizedFilename, compileData.compiled.css);
|
|
1460
|
-
}
|
|
1461
|
-
updateJS(compileData) {
|
|
1462
|
-
if (!compileData.ssr) {
|
|
1463
|
-
this._js.set(compileData.normalizedFilename, compileData.compiled.js);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
updateDependencies(compileData) {
|
|
1467
|
-
const id = compileData.normalizedFilename;
|
|
1468
|
-
const prevDependencies = this._dependencies.get(id) || [];
|
|
1469
|
-
const dependencies = compileData.dependencies;
|
|
1470
|
-
this._dependencies.set(id, dependencies);
|
|
1471
|
-
const removed = prevDependencies.filter((d) => !dependencies.includes(d));
|
|
1472
|
-
const added = dependencies.filter((d) => !prevDependencies.includes(d));
|
|
1473
|
-
added.forEach((d) => {
|
|
1474
|
-
if (!this._dependants.has(d)) {
|
|
1475
|
-
this._dependants.set(d, /* @__PURE__ */ new Set());
|
|
1476
|
-
}
|
|
1477
|
-
this._dependants.get(d).add(compileData.filename);
|
|
1478
|
-
});
|
|
1479
|
-
removed.forEach((d) => {
|
|
1480
|
-
this._dependants.get(d).delete(compileData.filename);
|
|
1481
|
-
});
|
|
1482
|
-
}
|
|
1483
|
-
remove(svelteRequest, keepDependencies = false) {
|
|
1484
|
-
const id = svelteRequest.normalizedFilename;
|
|
1485
|
-
let removed = false;
|
|
1486
|
-
if (this._errors.delete(id)) {
|
|
1487
|
-
removed = true;
|
|
1488
|
-
}
|
|
1489
|
-
if (this._js.delete(id)) {
|
|
1490
|
-
removed = true;
|
|
1491
|
-
}
|
|
1492
|
-
if (this._css.delete(id)) {
|
|
1493
|
-
removed = true;
|
|
1494
|
-
}
|
|
1495
|
-
if (!keepDependencies) {
|
|
1496
|
-
const dependencies = this._dependencies.get(id);
|
|
1497
|
-
if (dependencies) {
|
|
1498
|
-
removed = true;
|
|
1499
|
-
dependencies.forEach((d) => {
|
|
1500
|
-
const dependants = this._dependants.get(d);
|
|
1501
|
-
if (dependants && dependants.has(svelteRequest.filename)) {
|
|
1502
|
-
dependants.delete(svelteRequest.filename);
|
|
1503
|
-
}
|
|
1504
|
-
});
|
|
1505
|
-
this._dependencies.delete(id);
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
return removed;
|
|
1509
|
-
}
|
|
1510
|
-
getCSS(svelteRequest) {
|
|
1511
|
-
return this._css.get(svelteRequest.normalizedFilename);
|
|
1512
|
-
}
|
|
1513
|
-
getJS(svelteRequest) {
|
|
1514
|
-
if (!svelteRequest.ssr) {
|
|
1515
|
-
return this._js.get(svelteRequest.normalizedFilename);
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
getError(svelteRequest) {
|
|
1519
|
-
return this._errors.get(svelteRequest.normalizedFilename);
|
|
1520
|
-
}
|
|
1521
|
-
getDependants(path9) {
|
|
1522
|
-
const dependants = this._dependants.get(path9);
|
|
1523
|
-
return dependants ? [...dependants] : [];
|
|
1524
|
-
}
|
|
1525
|
-
getResolvedSvelteField(name, importer) {
|
|
1526
|
-
return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
|
|
1527
|
-
}
|
|
1528
|
-
setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
|
|
1529
|
-
this._resolvedSvelteFields.set(
|
|
1530
|
-
this._getResolvedSvelteFieldKey(importee, importer),
|
|
1531
|
-
resolvedSvelte
|
|
1532
|
-
);
|
|
1533
|
-
}
|
|
1534
|
-
_getResolvedSvelteFieldKey(importee, importer) {
|
|
1535
|
-
return importer ? `${importer} > ${importee}` : importee;
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
|
|
1539
1674
|
// src/utils/watch.ts
|
|
1540
|
-
var
|
|
1675
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
1541
1676
|
var import_path5 = __toESM(require("path"), 1);
|
|
1542
1677
|
function setupWatchers(options, cache, requestParser) {
|
|
1543
1678
|
const { server, configFile: svelteConfigFile } = options;
|
|
@@ -1549,7 +1684,7 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1549
1684
|
const emitChangeEventOnDependants = (filename) => {
|
|
1550
1685
|
const dependants = cache.getDependants(filename);
|
|
1551
1686
|
dependants.forEach((dependant) => {
|
|
1552
|
-
if (
|
|
1687
|
+
if (import_fs4.default.existsSync(dependant)) {
|
|
1553
1688
|
log.debug(
|
|
1554
1689
|
`emitting virtual change event for "${dependant}" because depdendency "${filename}" changed`
|
|
1555
1690
|
);
|
|
@@ -1610,7 +1745,7 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1610
1745
|
});
|
|
1611
1746
|
}
|
|
1612
1747
|
function ensureWatchedFile(watcher, file, root) {
|
|
1613
|
-
if (file && !file.startsWith(root + "/") && !file.includes("\0") &&
|
|
1748
|
+
if (file && !file.startsWith(root + "/") && !file.includes("\0") && import_fs4.default.existsSync(file)) {
|
|
1614
1749
|
watcher.add(import_path5.default.resolve(file));
|
|
1615
1750
|
}
|
|
1616
1751
|
}
|
|
@@ -1654,7 +1789,7 @@ function isBareImport(importee) {
|
|
|
1654
1789
|
}
|
|
1655
1790
|
|
|
1656
1791
|
// src/utils/optimizer.ts
|
|
1657
|
-
var
|
|
1792
|
+
var import_fs5 = require("fs");
|
|
1658
1793
|
var import_path7 = __toESM(require("path"), 1);
|
|
1659
1794
|
var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
1660
1795
|
"compilerOptions",
|
|
@@ -1672,11 +1807,11 @@ async function saveSvelteMetadata(cacheDir, options) {
|
|
|
1672
1807
|
});
|
|
1673
1808
|
let existingSvelteMetadata;
|
|
1674
1809
|
try {
|
|
1675
|
-
existingSvelteMetadata = await
|
|
1810
|
+
existingSvelteMetadata = await import_fs5.promises.readFile(svelteMetadataPath, "utf8");
|
|
1676
1811
|
} catch {
|
|
1677
1812
|
}
|
|
1678
|
-
await
|
|
1679
|
-
await
|
|
1813
|
+
await import_fs5.promises.mkdir(cacheDir, { recursive: true });
|
|
1814
|
+
await import_fs5.promises.writeFile(svelteMetadataPath, currentSvelteMetadata);
|
|
1680
1815
|
return currentSvelteMetadata !== existingSvelteMetadata;
|
|
1681
1816
|
}
|
|
1682
1817
|
function generateSvelteMetadata(options) {
|
|
@@ -1691,7 +1826,7 @@ function generateSvelteMetadata(options) {
|
|
|
1691
1826
|
var import_vite4 = require("vite");
|
|
1692
1827
|
var import_path8 = __toESM(require("path"), 1);
|
|
1693
1828
|
var import_url2 = require("url");
|
|
1694
|
-
var
|
|
1829
|
+
var import_fs6 = __toESM(require("fs"), 1);
|
|
1695
1830
|
|
|
1696
1831
|
// src/ui/inspector/utils.ts
|
|
1697
1832
|
var FS_PREFIX = `/@fs/`;
|
|
@@ -1768,8 +1903,8 @@ function svelteInspector() {
|
|
|
1768
1903
|
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1769
1904
|
} else if (id.startsWith(inspectorPath)) {
|
|
1770
1905
|
const file = idToFile(id);
|
|
1771
|
-
if (
|
|
1772
|
-
return await
|
|
1906
|
+
if (import_fs6.default.existsSync(file)) {
|
|
1907
|
+
return await import_fs6.default.promises.readFile(file, "utf-8");
|
|
1773
1908
|
} else {
|
|
1774
1909
|
log.error(`failed to find file for svelte-inspector: ${file}, referenced by id ${id}.`);
|
|
1775
1910
|
}
|
|
@@ -1805,6 +1940,111 @@ import 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
|
1805
1940
|
};
|
|
1806
1941
|
}
|
|
1807
1942
|
|
|
1943
|
+
// src/utils/vite-plugin-svelte-cache.ts
|
|
1944
|
+
var VitePluginSvelteCache = class {
|
|
1945
|
+
constructor() {
|
|
1946
|
+
this._css = /* @__PURE__ */ new Map();
|
|
1947
|
+
this._js = /* @__PURE__ */ new Map();
|
|
1948
|
+
this._dependencies = /* @__PURE__ */ new Map();
|
|
1949
|
+
this._dependants = /* @__PURE__ */ new Map();
|
|
1950
|
+
this._resolvedSvelteFields = /* @__PURE__ */ new Map();
|
|
1951
|
+
this._errors = /* @__PURE__ */ new Map();
|
|
1952
|
+
}
|
|
1953
|
+
update(compileData) {
|
|
1954
|
+
this._errors.delete(compileData.normalizedFilename);
|
|
1955
|
+
this.updateCSS(compileData);
|
|
1956
|
+
this.updateJS(compileData);
|
|
1957
|
+
this.updateDependencies(compileData);
|
|
1958
|
+
}
|
|
1959
|
+
has(svelteRequest) {
|
|
1960
|
+
const id = svelteRequest.normalizedFilename;
|
|
1961
|
+
return this._errors.has(id) || this._js.has(id) || this._css.has(id);
|
|
1962
|
+
}
|
|
1963
|
+
setError(svelteRequest, error) {
|
|
1964
|
+
this.remove(svelteRequest, true);
|
|
1965
|
+
this._errors.set(svelteRequest.normalizedFilename, error);
|
|
1966
|
+
}
|
|
1967
|
+
updateCSS(compileData) {
|
|
1968
|
+
this._css.set(compileData.normalizedFilename, compileData.compiled.css);
|
|
1969
|
+
}
|
|
1970
|
+
updateJS(compileData) {
|
|
1971
|
+
if (!compileData.ssr) {
|
|
1972
|
+
this._js.set(compileData.normalizedFilename, compileData.compiled.js);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
updateDependencies(compileData) {
|
|
1976
|
+
const id = compileData.normalizedFilename;
|
|
1977
|
+
const prevDependencies = this._dependencies.get(id) || [];
|
|
1978
|
+
const dependencies = compileData.dependencies;
|
|
1979
|
+
this._dependencies.set(id, dependencies);
|
|
1980
|
+
const removed = prevDependencies.filter((d) => !dependencies.includes(d));
|
|
1981
|
+
const added = dependencies.filter((d) => !prevDependencies.includes(d));
|
|
1982
|
+
added.forEach((d) => {
|
|
1983
|
+
if (!this._dependants.has(d)) {
|
|
1984
|
+
this._dependants.set(d, /* @__PURE__ */ new Set());
|
|
1985
|
+
}
|
|
1986
|
+
this._dependants.get(d).add(compileData.filename);
|
|
1987
|
+
});
|
|
1988
|
+
removed.forEach((d) => {
|
|
1989
|
+
this._dependants.get(d).delete(compileData.filename);
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
remove(svelteRequest, keepDependencies = false) {
|
|
1993
|
+
const id = svelteRequest.normalizedFilename;
|
|
1994
|
+
let removed = false;
|
|
1995
|
+
if (this._errors.delete(id)) {
|
|
1996
|
+
removed = true;
|
|
1997
|
+
}
|
|
1998
|
+
if (this._js.delete(id)) {
|
|
1999
|
+
removed = true;
|
|
2000
|
+
}
|
|
2001
|
+
if (this._css.delete(id)) {
|
|
2002
|
+
removed = true;
|
|
2003
|
+
}
|
|
2004
|
+
if (!keepDependencies) {
|
|
2005
|
+
const dependencies = this._dependencies.get(id);
|
|
2006
|
+
if (dependencies) {
|
|
2007
|
+
removed = true;
|
|
2008
|
+
dependencies.forEach((d) => {
|
|
2009
|
+
const dependants = this._dependants.get(d);
|
|
2010
|
+
if (dependants && dependants.has(svelteRequest.filename)) {
|
|
2011
|
+
dependants.delete(svelteRequest.filename);
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
this._dependencies.delete(id);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
return removed;
|
|
2018
|
+
}
|
|
2019
|
+
getCSS(svelteRequest) {
|
|
2020
|
+
return this._css.get(svelteRequest.normalizedFilename);
|
|
2021
|
+
}
|
|
2022
|
+
getJS(svelteRequest) {
|
|
2023
|
+
if (!svelteRequest.ssr) {
|
|
2024
|
+
return this._js.get(svelteRequest.normalizedFilename);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
getError(svelteRequest) {
|
|
2028
|
+
return this._errors.get(svelteRequest.normalizedFilename);
|
|
2029
|
+
}
|
|
2030
|
+
getDependants(path9) {
|
|
2031
|
+
const dependants = this._dependants.get(path9);
|
|
2032
|
+
return dependants ? [...dependants] : [];
|
|
2033
|
+
}
|
|
2034
|
+
getResolvedSvelteField(name, importer) {
|
|
2035
|
+
return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
|
|
2036
|
+
}
|
|
2037
|
+
setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
|
|
2038
|
+
this._resolvedSvelteFields.set(
|
|
2039
|
+
this._getResolvedSvelteFieldKey(importee, importer),
|
|
2040
|
+
resolvedSvelte
|
|
2041
|
+
);
|
|
2042
|
+
}
|
|
2043
|
+
_getResolvedSvelteFieldKey(importee, importer) {
|
|
2044
|
+
return importer ? `${importer} > ${importee}` : importee;
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
|
|
1808
2048
|
// src/index.ts
|
|
1809
2049
|
function svelte(inlineOptions) {
|
|
1810
2050
|
if (process.env.DEBUG != null) {
|
|
@@ -1869,7 +2109,7 @@ function svelte(inlineOptions) {
|
|
|
1869
2109
|
}
|
|
1870
2110
|
if (viteConfig.assetsInclude(filename)) {
|
|
1871
2111
|
log.debug(`load returns raw content for ${filename}`);
|
|
1872
|
-
return
|
|
2112
|
+
return import_fs7.default.readFileSync(filename, "utf-8");
|
|
1873
2113
|
}
|
|
1874
2114
|
}
|
|
1875
2115
|
},
|
|
@@ -1903,7 +2143,7 @@ function svelte(inlineOptions) {
|
|
|
1903
2143
|
return resolvedSvelteSSR;
|
|
1904
2144
|
}
|
|
1905
2145
|
const scan = !!opts?.scan;
|
|
1906
|
-
const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !(0,
|
|
2146
|
+
const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !(0, import_vitefu4.isDepExcluded)(importee, viteConfig.optimizeDeps?.exclude ?? []);
|
|
1907
2147
|
if (ssr || scan || !isPrebundled) {
|
|
1908
2148
|
try {
|
|
1909
2149
|
const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
@@ -1963,6 +2203,9 @@ function svelte(inlineOptions) {
|
|
|
1963
2203
|
throw toRollupError(e, options);
|
|
1964
2204
|
}
|
|
1965
2205
|
}
|
|
2206
|
+
},
|
|
2207
|
+
async buildEnd() {
|
|
2208
|
+
await options.stats?.finishAll();
|
|
1966
2209
|
}
|
|
1967
2210
|
}
|
|
1968
2211
|
];
|