@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 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
- plugins: [
14
- svelte({
15
- /* plugin options */
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.4_typescript@4.6.3/node_modules/tsup/assets/cjs_shims.js
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 import_fs6 = __toESM(require("fs"), 1);
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")).substr(0, hash_length);
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, path8 = []) {
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: path8 });
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) => path8.includes(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) => path8.concat(x).join(">")));
603
- dependencyNames = dependencyNames.filter((name) => !path8.includes(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 (path8.length === 3) {
606
- log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
610
+ if (path9.length === 3) {
611
+ log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
607
612
  }
608
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
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 merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, defaultOptions), svelteConfig), inlineOptions), {
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 merged = __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), preResolveOptions2), {
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 _a;
1208
- return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.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 _a;
1212
- return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${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(path8) {
1345
- const dependants = this._dependants.get(path8);
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
- listenerCollection.change.push(restartOnConfigChange);
1418
- listenerCollection.unlink.push(restartOnConfigChange);
1419
- } else {
1420
- listenerCollection.add.push(restartOnConfigAdd);
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
- return {
1520
- name: "vite-plugin-svelte",
1521
- enforce: "pre",
1522
- async config(config, configEnv) {
1523
- if (process.env.DEBUG) {
1524
- log.setLevel("debug");
1525
- } else if (config.logLevel) {
1526
- log.setLevel(config.logLevel);
1527
- }
1528
- options = await preResolveOptions(inlineOptions, config, configEnv);
1529
- const extraViteConfig = buildExtraViteConfig(options, config);
1530
- log.debug("additional vite config", extraViteConfig);
1531
- return extraViteConfig;
1532
- },
1533
- async configResolved(config) {
1534
- options = resolveOptions(options, config);
1535
- patchResolvedViteConfig(config, options);
1536
- requestParser = buildIdParser(options);
1537
- compileSvelte2 = createCompileSvelte(options);
1538
- viteConfig = config;
1539
- log.debug("resolved options", options);
1540
- },
1541
- async buildStart() {
1542
- if (!options.experimental.prebundleSvelteLibraries)
1543
- return;
1544
- const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1545
- if (isSvelteMetadataChanged) {
1546
- viteConfig.server.force = true;
1547
- }
1548
- },
1549
- configureServer(server) {
1550
- options.server = server;
1551
- setupWatchers(options, cache, requestParser);
1552
- },
1553
- load(id, opts) {
1554
- const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
1555
- const svelteRequest = requestParser(id, !!ssr);
1556
- if (svelteRequest) {
1557
- const { filename, query } = svelteRequest;
1558
- if (query.svelte && query.type === "style") {
1559
- const css = cache.getCSS(svelteRequest);
1560
- if (css) {
1561
- log.debug(`load returns css for ${filename}`);
1562
- return css;
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
- if (viteConfig.assetsInclude(filename)) {
1566
- log.debug(`load returns raw content for ${filename}`);
1567
- return import_fs6.default.readFileSync(filename, "utf-8");
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
- async resolveId(importee, importer, opts) {
1572
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1573
- const svelteRequest = requestParser(importee, ssr);
1574
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1575
- if (svelteRequest.query.type === "style") {
1576
- log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1577
- return svelteRequest.cssId;
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
- log.debug(`resolveId resolved ${importee}`);
1580
- return importee;
1581
- }
1582
- if (ssr && importee === "svelte") {
1583
- if (!resolvedSvelteSSR) {
1584
- resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
1585
- log.debug("resolved svelte to svelte/ssr");
1586
- return svelteSSR;
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
- return resolvedSvelteSSR;
1593
- }
1594
- try {
1595
- const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1596
- if (resolved) {
1597
- log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
1598
- return resolved;
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
- } catch (e) {
1601
- log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
1602
- }
1603
- },
1604
- async transform(code, id, opts) {
1605
- var _a;
1606
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1607
- const svelteRequest = requestParser(id, ssr);
1608
- if (!svelteRequest || svelteRequest.query.svelte) {
1609
- return;
1610
- }
1611
- let compileData;
1612
- try {
1613
- compileData = await compileSvelte2(svelteRequest, code, options);
1614
- } catch (e) {
1615
- throw toRollupError(e, options);
1616
- }
1617
- logCompilerWarnings(compileData.compiled.warnings, options);
1618
- cache.update(compileData);
1619
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
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
- log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
1625
- return compileData.compiled.js;
1626
- },
1627
- handleHotUpdate(ctx) {
1628
- if (!options.hot || !options.emitCss) {
1629
- return;
1630
- }
1631
- const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
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 = {