@sveltejs/vite-plugin-svelte 1.0.0-next.41 → 1.0.0-next.44
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/README.md +5 -5
- package/dist/index.cjs +281 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +47 -2
- package/dist/index.js +280 -152
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
- package/src/index.ts +162 -135
- package/src/ui/inspector/Inspector.svelte +245 -0
- package/src/ui/inspector/load-inspector.js +15 -0
- package/src/ui/inspector/plugin.ts +106 -0
- package/src/utils/compile.ts +4 -0
- package/src/utils/hash.ts +1 -1
- package/src/utils/load-svelte-config.ts +3 -0
- package/src/utils/options.ts +79 -26
- package/src/utils/watch.ts +22 -18
package/README.md
CHANGED
|
@@ -10,11 +10,11 @@ import { defineConfig } from 'vite';
|
|
|
10
10
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
11
11
|
|
|
12
12
|
export default defineConfig({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
plugins: [
|
|
14
|
+
svelte({
|
|
15
|
+
/* plugin options */
|
|
16
|
+
})
|
|
17
|
+
]
|
|
18
18
|
});
|
|
19
19
|
```
|
|
20
20
|
|
package/dist/index.cjs
CHANGED
|
@@ -43,12 +43,12 @@ __export(src_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(src_exports);
|
|
45
45
|
|
|
46
|
-
// ../../node_modules/.pnpm/tsup@5.12.
|
|
46
|
+
// ../../node_modules/.pnpm/tsup@5.12.7/node_modules/tsup/assets/cjs_shims.js
|
|
47
47
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
48
48
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
49
49
|
|
|
50
50
|
// src/index.ts
|
|
51
|
-
var
|
|
51
|
+
var import_fs7 = __toESM(require("fs"), 1);
|
|
52
52
|
|
|
53
53
|
// src/utils/log.ts
|
|
54
54
|
var import_colors = require("kleur/colors");
|
|
@@ -279,7 +279,7 @@ function safeBase64Hash(input) {
|
|
|
279
279
|
}
|
|
280
280
|
const md5 = crypto.createHash("md5");
|
|
281
281
|
md5.update(input);
|
|
282
|
-
const hash = toSafe(md5.digest("base64")).
|
|
282
|
+
const hash = toSafe(md5.digest("base64")).slice(0, hash_length);
|
|
283
283
|
hashes[input] = hash;
|
|
284
284
|
return hash;
|
|
285
285
|
}
|
|
@@ -294,8 +294,9 @@ function toSafe(base64) {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
// src/utils/compile.ts
|
|
297
|
+
var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
297
298
|
var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
|
|
298
|
-
var _a, _b;
|
|
299
|
+
var _a, _b, _c;
|
|
299
300
|
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
|
|
300
301
|
const { emitCss = true } = options;
|
|
301
302
|
const dependencies = [];
|
|
@@ -358,6 +359,7 @@ import ${JSON.stringify(cssId)};
|
|
|
358
359
|
return {
|
|
359
360
|
filename,
|
|
360
361
|
normalizedFilename,
|
|
362
|
+
lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
|
|
361
363
|
compiled,
|
|
362
364
|
ssr,
|
|
363
365
|
dependencies
|
|
@@ -476,6 +478,9 @@ var knownSvelteConfigNames = [
|
|
|
476
478
|
];
|
|
477
479
|
var dynamicImportDefault = new Function("path", 'return import(path + "?t=" + Date.now()).then(m => m.default)');
|
|
478
480
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
481
|
+
if (inlineOptions.configFile === false) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
479
484
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
480
485
|
if (configFile) {
|
|
481
486
|
let err;
|
|
@@ -586,7 +591,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
|
|
|
586
591
|
].filter((dep) => !is_common_without_svelte_field(dep));
|
|
587
592
|
return getSvelteDependencies(deps, root);
|
|
588
593
|
}
|
|
589
|
-
function getSvelteDependencies(deps, pkgDir,
|
|
594
|
+
function getSvelteDependencies(deps, pkgDir, path9 = []) {
|
|
590
595
|
const result = [];
|
|
591
596
|
const localRequire = (0, import_module2.createRequire)(`${pkgDir}/package.json`);
|
|
592
597
|
const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
|
|
@@ -594,18 +599,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
|
|
|
594
599
|
const type = getSvelteDependencyType(pkg);
|
|
595
600
|
if (!type)
|
|
596
601
|
continue;
|
|
597
|
-
result.push({ name: pkg.name, type, pkg, dir, path:
|
|
602
|
+
result.push({ name: pkg.name, type, pkg, dir, path: path9 });
|
|
598
603
|
if (type === "component-library" && pkg.dependencies) {
|
|
599
604
|
let dependencyNames = Object.keys(pkg.dependencies);
|
|
600
|
-
const circular = dependencyNames.filter((name) =>
|
|
605
|
+
const circular = dependencyNames.filter((name) => path9.includes(name));
|
|
601
606
|
if (circular.length > 0) {
|
|
602
|
-
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) =>
|
|
603
|
-
dependencyNames = dependencyNames.filter((name) => !
|
|
607
|
+
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">")));
|
|
608
|
+
dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
|
|
604
609
|
}
|
|
605
|
-
if (
|
|
606
|
-
log.debug.once(`encountered deep svelte dependency tree: ${
|
|
610
|
+
if (path9.length === 3) {
|
|
611
|
+
log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
|
|
607
612
|
}
|
|
608
|
-
result.push(...getSvelteDependencies(dependencyNames, dir,
|
|
613
|
+
result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
|
|
609
614
|
}
|
|
610
615
|
}
|
|
611
616
|
return result;
|
|
@@ -1068,6 +1073,7 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1068
1073
|
}
|
|
1069
1074
|
|
|
1070
1075
|
// src/utils/options.ts
|
|
1076
|
+
var import_deepmerge = __toESM(require("deepmerge"), 1);
|
|
1071
1077
|
var knownOptions = /* @__PURE__ */ new Set([
|
|
1072
1078
|
"configFile",
|
|
1073
1079
|
"include",
|
|
@@ -1080,7 +1086,8 @@ var knownOptions = /* @__PURE__ */ new Set([
|
|
|
1080
1086
|
"hot",
|
|
1081
1087
|
"ignorePluginPreprocessors",
|
|
1082
1088
|
"disableDependencyReinclusion",
|
|
1083
|
-
"experimental"
|
|
1089
|
+
"experimental",
|
|
1090
|
+
"kit"
|
|
1084
1091
|
]);
|
|
1085
1092
|
function validateInlineOptions(inlineOptions) {
|
|
1086
1093
|
const invalidKeys = Object.keys(inlineOptions || {}).filter((key) => !knownOptions.has(key));
|
|
@@ -1100,19 +1107,27 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1100
1107
|
}
|
|
1101
1108
|
};
|
|
1102
1109
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
|
|
1103
|
-
const
|
|
1104
|
-
compilerOptions: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.compilerOptions), svelteConfig == null ? void 0 : svelteConfig.compilerOptions), inlineOptions == null ? void 0 : inlineOptions.compilerOptions),
|
|
1105
|
-
experimental: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.experimental), svelteConfig == null ? void 0 : svelteConfig.experimental), inlineOptions == null ? void 0 : inlineOptions.experimental),
|
|
1110
|
+
const extraOptions = {
|
|
1106
1111
|
root: viteConfigWithResolvedRoot.root,
|
|
1107
1112
|
isBuild: viteEnv.command === "build",
|
|
1108
1113
|
isServe: viteEnv.command === "serve",
|
|
1109
1114
|
isDebug: process.env.DEBUG != null
|
|
1110
|
-
}
|
|
1115
|
+
};
|
|
1116
|
+
const merged = mergeConfigs(defaultOptions, svelteConfig, inlineOptions, extraOptions);
|
|
1111
1117
|
if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
|
|
1112
1118
|
merged.configFile = svelteConfig.configFile;
|
|
1113
1119
|
}
|
|
1114
1120
|
return merged;
|
|
1115
1121
|
}
|
|
1122
|
+
function mergeConfigs(...configs) {
|
|
1123
|
+
let result = {};
|
|
1124
|
+
for (const config of configs.filter(Boolean)) {
|
|
1125
|
+
result = (0, import_deepmerge.default)(result, config, {
|
|
1126
|
+
arrayMerge: (target, source) => source ?? target
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1116
1131
|
function resolveOptions(preResolveOptions2, viteConfig) {
|
|
1117
1132
|
const defaultOptions = {
|
|
1118
1133
|
hot: viteConfig.isProduction ? false : { injectCss: !preResolveOptions2.emitCss },
|
|
@@ -1121,11 +1136,11 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1121
1136
|
dev: !viteConfig.isProduction
|
|
1122
1137
|
}
|
|
1123
1138
|
};
|
|
1124
|
-
const
|
|
1125
|
-
compilerOptions: __spreadValues(__spreadValues({}, defaultOptions.compilerOptions), preResolveOptions2.compilerOptions),
|
|
1139
|
+
const extraOptions = {
|
|
1126
1140
|
root: viteConfig.root,
|
|
1127
1141
|
isProduction: viteConfig.isProduction
|
|
1128
|
-
}
|
|
1142
|
+
};
|
|
1143
|
+
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1129
1144
|
addExtraPreprocessors(merged, viteConfig);
|
|
1130
1145
|
enforceOptionsForHmr(merged);
|
|
1131
1146
|
enforceOptionsForProduction(merged);
|
|
@@ -1178,6 +1193,7 @@ function resolveViteRoot(viteConfig) {
|
|
|
1178
1193
|
return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
|
|
1179
1194
|
}
|
|
1180
1195
|
function buildExtraViteConfig(options, config) {
|
|
1196
|
+
var _a;
|
|
1181
1197
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1182
1198
|
const extraViteConfig = {
|
|
1183
1199
|
resolve: {
|
|
@@ -1188,7 +1204,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1188
1204
|
if (options.isServe) {
|
|
1189
1205
|
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
|
|
1190
1206
|
}
|
|
1191
|
-
if (options.experimental.prebundleSvelteLibraries) {
|
|
1207
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1192
1208
|
extraViteConfig.optimizeDeps = __spreadProps(__spreadValues({}, extraViteConfig.optimizeDeps), {
|
|
1193
1209
|
extensions: options.extensions ?? [".svelte"],
|
|
1194
1210
|
esbuildOptions: {
|
|
@@ -1201,15 +1217,16 @@ function buildExtraViteConfig(options, config) {
|
|
|
1201
1217
|
return extraViteConfig;
|
|
1202
1218
|
}
|
|
1203
1219
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1220
|
+
var _a;
|
|
1204
1221
|
const include = [];
|
|
1205
1222
|
const exclude = ["svelte-hmr"];
|
|
1206
1223
|
const isIncluded = (dep) => {
|
|
1207
|
-
var
|
|
1208
|
-
return include.includes(dep) || ((
|
|
1224
|
+
var _a2;
|
|
1225
|
+
return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
|
|
1209
1226
|
};
|
|
1210
1227
|
const isExcluded = (dep) => {
|
|
1211
|
-
var
|
|
1212
|
-
return exclude.includes(dep) || ((
|
|
1228
|
+
var _a2;
|
|
1229
|
+
return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1213
1230
|
};
|
|
1214
1231
|
if (!isExcluded("svelte")) {
|
|
1215
1232
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1218,7 +1235,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1218
1235
|
} else {
|
|
1219
1236
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1220
1237
|
}
|
|
1221
|
-
if (options.experimental.prebundleSvelteLibraries) {
|
|
1238
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1222
1239
|
return { include, exclude };
|
|
1223
1240
|
}
|
|
1224
1241
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1341,8 +1358,8 @@ var VitePluginSvelteCache = class {
|
|
|
1341
1358
|
return this._js.get(svelteRequest.normalizedFilename);
|
|
1342
1359
|
}
|
|
1343
1360
|
}
|
|
1344
|
-
getDependants(
|
|
1345
|
-
const dependants = this._dependants.get(
|
|
1361
|
+
getDependants(path9) {
|
|
1362
|
+
const dependants = this._dependants.get(path9);
|
|
1346
1363
|
return dependants ? [...dependants] : [];
|
|
1347
1364
|
}
|
|
1348
1365
|
getResolvedSvelteField(name, importer) {
|
|
@@ -1397,27 +1414,29 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1397
1414
|
server.restart();
|
|
1398
1415
|
}
|
|
1399
1416
|
};
|
|
1400
|
-
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
|
|
1401
|
-
const restartOnConfigAdd = (filename) => {
|
|
1402
|
-
if (possibleSvelteConfigs.includes(filename)) {
|
|
1403
|
-
triggerViteRestart(filename);
|
|
1404
|
-
}
|
|
1405
|
-
};
|
|
1406
|
-
const restartOnConfigChange = (filename) => {
|
|
1407
|
-
if (filename === svelteConfigFile) {
|
|
1408
|
-
triggerViteRestart(filename);
|
|
1409
|
-
}
|
|
1410
|
-
};
|
|
1411
1417
|
const listenerCollection = {
|
|
1412
1418
|
add: [],
|
|
1413
1419
|
change: [emitChangeEventOnDependants],
|
|
1414
1420
|
unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
|
|
1415
1421
|
};
|
|
1416
|
-
if (svelteConfigFile) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1422
|
+
if (svelteConfigFile !== false) {
|
|
1423
|
+
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
|
|
1424
|
+
const restartOnConfigAdd = (filename) => {
|
|
1425
|
+
if (possibleSvelteConfigs.includes(filename)) {
|
|
1426
|
+
triggerViteRestart(filename);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
const restartOnConfigChange = (filename) => {
|
|
1430
|
+
if (filename === svelteConfigFile) {
|
|
1431
|
+
triggerViteRestart(filename);
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
if (svelteConfigFile) {
|
|
1435
|
+
listenerCollection.change.push(restartOnConfigChange);
|
|
1436
|
+
listenerCollection.unlink.push(restartOnConfigChange);
|
|
1437
|
+
} else {
|
|
1438
|
+
listenerCollection.add.push(restartOnConfigAdd);
|
|
1439
|
+
}
|
|
1421
1440
|
}
|
|
1422
1441
|
Object.entries(listenerCollection).forEach(([evt, listeners]) => {
|
|
1423
1442
|
if (listeners.length > 0) {
|
|
@@ -1504,6 +1523,101 @@ function generateSvelteMetadata(options) {
|
|
|
1504
1523
|
return metadata;
|
|
1505
1524
|
}
|
|
1506
1525
|
|
|
1526
|
+
// src/ui/inspector/plugin.ts
|
|
1527
|
+
var import_vite4 = require("vite");
|
|
1528
|
+
var import_path8 = __toESM(require("path"), 1);
|
|
1529
|
+
var import_url2 = require("url");
|
|
1530
|
+
var import_fs6 = __toESM(require("fs"), 1);
|
|
1531
|
+
var defaultInspectorOptions = {
|
|
1532
|
+
toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
|
|
1533
|
+
holdMode: false,
|
|
1534
|
+
showToggleButton: "active",
|
|
1535
|
+
toggleButtonPos: "top-right",
|
|
1536
|
+
customStyles: true
|
|
1537
|
+
};
|
|
1538
|
+
function getInspectorPath() {
|
|
1539
|
+
const pluginPath = (0, import_vite4.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
|
|
1540
|
+
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1541
|
+
}
|
|
1542
|
+
function svelteInspector() {
|
|
1543
|
+
const inspectorPath = getInspectorPath();
|
|
1544
|
+
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
|
|
1545
|
+
let inspectorOptions;
|
|
1546
|
+
let appendTo;
|
|
1547
|
+
let disabled = false;
|
|
1548
|
+
return {
|
|
1549
|
+
name: "vite-plugin-svelte:inspector",
|
|
1550
|
+
apply: "serve",
|
|
1551
|
+
enforce: "pre",
|
|
1552
|
+
configResolved(config) {
|
|
1553
|
+
var _a, _b, _c;
|
|
1554
|
+
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1555
|
+
if ((_c = (_b = (_a = vps == null ? void 0 : vps.api) == null ? void 0 : _a.options) == null ? void 0 : _b.experimental) == null ? void 0 : _c.inspector) {
|
|
1556
|
+
inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
|
|
1557
|
+
}
|
|
1558
|
+
if (!vps || !inspectorOptions) {
|
|
1559
|
+
log.debug("inspector disabled, could not find config");
|
|
1560
|
+
disabled = true;
|
|
1561
|
+
} else {
|
|
1562
|
+
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1563
|
+
const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
|
|
1564
|
+
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
1565
|
+
}
|
|
1566
|
+
appendTo = inspectorOptions.appendTo;
|
|
1567
|
+
}
|
|
1568
|
+
},
|
|
1569
|
+
async resolveId(importee, importer, options) {
|
|
1570
|
+
if ((options == null ? void 0 : options.ssr) || disabled) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
1574
|
+
return importee;
|
|
1575
|
+
} else if (importee.startsWith("virtual:svelte-inspector-path:")) {
|
|
1576
|
+
const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
|
|
1577
|
+
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
|
|
1578
|
+
return resolved;
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1581
|
+
async load(id, options) {
|
|
1582
|
+
if ((options == null ? void 0 : options.ssr) || disabled) {
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
if (id === "virtual:svelte-inspector-options") {
|
|
1586
|
+
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1587
|
+
} else if (id.startsWith(inspectorPath)) {
|
|
1588
|
+
return await import_fs6.default.promises.readFile(id, "utf-8");
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
transform(code, id, options) {
|
|
1592
|
+
if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
if (id.endsWith(appendTo)) {
|
|
1596
|
+
return { code: `${code}
|
|
1597
|
+
import 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
1598
|
+
}
|
|
1599
|
+
},
|
|
1600
|
+
transformIndexHtml(html) {
|
|
1601
|
+
if (disabled || appendTo) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
return {
|
|
1605
|
+
html,
|
|
1606
|
+
tags: [
|
|
1607
|
+
{
|
|
1608
|
+
tag: "script",
|
|
1609
|
+
injectTo: "body",
|
|
1610
|
+
attrs: {
|
|
1611
|
+
type: "module",
|
|
1612
|
+
src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
]
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1507
1621
|
// src/index.ts
|
|
1508
1622
|
function svelte(inlineOptions) {
|
|
1509
1623
|
if (process.env.DEBUG != null) {
|
|
@@ -1516,124 +1630,138 @@ function svelte(inlineOptions) {
|
|
|
1516
1630
|
let viteConfig;
|
|
1517
1631
|
let compileSvelte2;
|
|
1518
1632
|
let resolvedSvelteSSR;
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1633
|
+
const api = {};
|
|
1634
|
+
const plugins = [
|
|
1635
|
+
{
|
|
1636
|
+
name: "vite-plugin-svelte",
|
|
1637
|
+
enforce: "pre",
|
|
1638
|
+
api,
|
|
1639
|
+
async config(config, configEnv) {
|
|
1640
|
+
if (process.env.DEBUG) {
|
|
1641
|
+
log.setLevel("debug");
|
|
1642
|
+
} else if (config.logLevel) {
|
|
1643
|
+
log.setLevel(config.logLevel);
|
|
1644
|
+
}
|
|
1645
|
+
options = await preResolveOptions(inlineOptions, config, configEnv);
|
|
1646
|
+
const extraViteConfig = buildExtraViteConfig(options, config);
|
|
1647
|
+
log.debug("additional vite config", extraViteConfig);
|
|
1648
|
+
return extraViteConfig;
|
|
1649
|
+
},
|
|
1650
|
+
async configResolved(config) {
|
|
1651
|
+
options = resolveOptions(options, config);
|
|
1652
|
+
patchResolvedViteConfig(config, options);
|
|
1653
|
+
requestParser = buildIdParser(options);
|
|
1654
|
+
compileSvelte2 = createCompileSvelte(options);
|
|
1655
|
+
viteConfig = config;
|
|
1656
|
+
api.options = options;
|
|
1657
|
+
log.debug("resolved options", options);
|
|
1658
|
+
},
|
|
1659
|
+
async buildStart() {
|
|
1660
|
+
var _a;
|
|
1661
|
+
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1662
|
+
return;
|
|
1663
|
+
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1664
|
+
if (isSvelteMetadataChanged) {
|
|
1665
|
+
viteConfig.server.force = true;
|
|
1666
|
+
}
|
|
1667
|
+
},
|
|
1668
|
+
configureServer(server) {
|
|
1669
|
+
options.server = server;
|
|
1670
|
+
setupWatchers(options, cache, requestParser);
|
|
1671
|
+
},
|
|
1672
|
+
load(id, opts) {
|
|
1673
|
+
const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
|
|
1674
|
+
const svelteRequest = requestParser(id, !!ssr);
|
|
1675
|
+
if (svelteRequest) {
|
|
1676
|
+
const { filename, query } = svelteRequest;
|
|
1677
|
+
if (query.svelte && query.type === "style") {
|
|
1678
|
+
const css = cache.getCSS(svelteRequest);
|
|
1679
|
+
if (css) {
|
|
1680
|
+
log.debug(`load returns css for ${filename}`);
|
|
1681
|
+
return css;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
if (viteConfig.assetsInclude(filename)) {
|
|
1685
|
+
log.debug(`load returns raw content for ${filename}`);
|
|
1686
|
+
return import_fs7.default.readFileSync(filename, "utf-8");
|
|
1563
1687
|
}
|
|
1564
1688
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1689
|
+
},
|
|
1690
|
+
async resolveId(importee, importer, opts) {
|
|
1691
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1692
|
+
const svelteRequest = requestParser(importee, ssr);
|
|
1693
|
+
if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
|
|
1694
|
+
if (svelteRequest.query.type === "style") {
|
|
1695
|
+
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
1696
|
+
return svelteRequest.cssId;
|
|
1697
|
+
}
|
|
1698
|
+
log.debug(`resolveId resolved ${importee}`);
|
|
1699
|
+
return importee;
|
|
1568
1700
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1701
|
+
if (ssr && importee === "svelte") {
|
|
1702
|
+
if (!resolvedSvelteSSR) {
|
|
1703
|
+
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
|
|
1704
|
+
log.debug("resolved svelte to svelte/ssr");
|
|
1705
|
+
return svelteSSR;
|
|
1706
|
+
}, (err) => {
|
|
1707
|
+
log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
|
|
1708
|
+
return null;
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
return resolvedSvelteSSR;
|
|
1578
1712
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}, (err) => {
|
|
1588
|
-
log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
|
|
1589
|
-
return null;
|
|
1590
|
-
});
|
|
1713
|
+
try {
|
|
1714
|
+
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
1715
|
+
if (resolved) {
|
|
1716
|
+
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
|
|
1717
|
+
return resolved;
|
|
1718
|
+
}
|
|
1719
|
+
} catch (e) {
|
|
1720
|
+
log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
|
|
1591
1721
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
return
|
|
1722
|
+
},
|
|
1723
|
+
async transform(code, id, opts) {
|
|
1724
|
+
var _a;
|
|
1725
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1726
|
+
const svelteRequest = requestParser(id, ssr);
|
|
1727
|
+
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1728
|
+
return;
|
|
1599
1729
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
compileData.dependencies.forEach((d) => {
|
|
1621
|
-
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1730
|
+
let compileData;
|
|
1731
|
+
try {
|
|
1732
|
+
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1733
|
+
} catch (e) {
|
|
1734
|
+
throw toRollupError(e, options);
|
|
1735
|
+
}
|
|
1736
|
+
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1737
|
+
cache.update(compileData);
|
|
1738
|
+
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|
|
1739
|
+
compileData.dependencies.forEach((d) => {
|
|
1740
|
+
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
1744
|
+
return __spreadProps(__spreadValues({}, compileData.compiled.js), {
|
|
1745
|
+
meta: {
|
|
1746
|
+
vite: {
|
|
1747
|
+
lang: compileData.lang
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1622
1750
|
});
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
if (svelteRequest) {
|
|
1633
|
-
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1751
|
+
},
|
|
1752
|
+
handleHotUpdate(ctx) {
|
|
1753
|
+
if (!options.hot || !options.emitCss) {
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
|
|
1757
|
+
if (svelteRequest) {
|
|
1758
|
+
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1759
|
+
}
|
|
1634
1760
|
}
|
|
1635
1761
|
}
|
|
1636
|
-
|
|
1762
|
+
];
|
|
1763
|
+
plugins.push(svelteInspector());
|
|
1764
|
+
return plugins.filter(Boolean);
|
|
1637
1765
|
}
|
|
1638
1766
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1639
1767
|
0 && (module.exports = {
|