@sveltejs/vite-plugin-svelte 1.0.0-next.39 → 1.0.0-next.42
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 +85 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +75 -81
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +9 -3
- package/src/utils/esbuild.ts +3 -26
- package/src/utils/hash.ts +1 -1
- package/src/utils/load-svelte-config.ts +3 -0
- package/src/utils/optimizer.ts +17 -22
- package/src/utils/options.ts +42 -15
- package/src/utils/preprocess.ts +6 -2
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
|
@@ -21,35 +21,29 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
24
|
var __export = (target, all) => {
|
|
26
25
|
for (var name in all)
|
|
27
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
27
|
};
|
|
29
|
-
var
|
|
30
|
-
if (
|
|
31
|
-
for (let key of __getOwnPropNames(
|
|
32
|
-
if (!__hasOwnProp.call(
|
|
33
|
-
__defProp(
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
33
|
}
|
|
35
|
-
return
|
|
34
|
+
return to;
|
|
36
35
|
};
|
|
37
|
-
var __toESM = (
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
41
|
-
return (module2, temp) => {
|
|
42
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
43
|
-
};
|
|
44
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
38
|
|
|
46
39
|
// src/index.ts
|
|
47
40
|
var src_exports = {};
|
|
48
41
|
__export(src_exports, {
|
|
49
42
|
svelte: () => svelte
|
|
50
43
|
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
51
45
|
|
|
52
|
-
// ../../node_modules/.pnpm/tsup@5.
|
|
46
|
+
// ../../node_modules/.pnpm/tsup@5.12.5_typescript@4.6.3/node_modules/tsup/assets/cjs_shims.js
|
|
53
47
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
54
48
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
55
49
|
|
|
@@ -285,7 +279,7 @@ function safeBase64Hash(input) {
|
|
|
285
279
|
}
|
|
286
280
|
const md5 = crypto.createHash("md5");
|
|
287
281
|
md5.update(input);
|
|
288
|
-
const hash = toSafe(md5.digest("base64")).
|
|
282
|
+
const hash = toSafe(md5.digest("base64")).slice(0, hash_length);
|
|
289
283
|
hashes[input] = hash;
|
|
290
284
|
return hash;
|
|
291
285
|
}
|
|
@@ -482,6 +476,9 @@ var knownSvelteConfigNames = [
|
|
|
482
476
|
];
|
|
483
477
|
var dynamicImportDefault = new Function("path", 'return import(path + "?t=" + Date.now()).then(m => m.default)');
|
|
484
478
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
479
|
+
if (inlineOptions.configFile === false) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
485
482
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
486
483
|
if (configFile) {
|
|
487
484
|
let err;
|
|
@@ -562,7 +559,7 @@ var SVELTE_HMR_IMPORTS = [
|
|
|
562
559
|
];
|
|
563
560
|
|
|
564
561
|
// src/utils/options.ts
|
|
565
|
-
var
|
|
562
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
566
563
|
|
|
567
564
|
// src/utils/dependencies.ts
|
|
568
565
|
var import_path2 = __toESM(require("path"), 1);
|
|
@@ -592,7 +589,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
|
|
|
592
589
|
].filter((dep) => !is_common_without_svelte_field(dep));
|
|
593
590
|
return getSvelteDependencies(deps, root);
|
|
594
591
|
}
|
|
595
|
-
function getSvelteDependencies(deps, pkgDir,
|
|
592
|
+
function getSvelteDependencies(deps, pkgDir, path8 = []) {
|
|
596
593
|
const result = [];
|
|
597
594
|
const localRequire = (0, import_module2.createRequire)(`${pkgDir}/package.json`);
|
|
598
595
|
const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
|
|
@@ -600,18 +597,18 @@ function getSvelteDependencies(deps, pkgDir, path7 = []) {
|
|
|
600
597
|
const type = getSvelteDependencyType(pkg);
|
|
601
598
|
if (!type)
|
|
602
599
|
continue;
|
|
603
|
-
result.push({ name: pkg.name, type, pkg, dir, path:
|
|
600
|
+
result.push({ name: pkg.name, type, pkg, dir, path: path8 });
|
|
604
601
|
if (type === "component-library" && pkg.dependencies) {
|
|
605
602
|
let dependencyNames = Object.keys(pkg.dependencies);
|
|
606
|
-
const circular = dependencyNames.filter((name) =>
|
|
603
|
+
const circular = dependencyNames.filter((name) => path8.includes(name));
|
|
607
604
|
if (circular.length > 0) {
|
|
608
|
-
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) =>
|
|
609
|
-
dependencyNames = dependencyNames.filter((name) => !
|
|
605
|
+
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">")));
|
|
606
|
+
dependencyNames = dependencyNames.filter((name) => !path8.includes(name));
|
|
610
607
|
}
|
|
611
|
-
if (
|
|
612
|
-
log.debug.once(`encountered deep svelte dependency tree: ${
|
|
608
|
+
if (path8.length === 3) {
|
|
609
|
+
log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
|
|
613
610
|
}
|
|
614
|
-
result.push(...getSvelteDependencies(dependencyNames, dir,
|
|
611
|
+
result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
|
|
615
612
|
}
|
|
616
613
|
}
|
|
617
614
|
return result;
|
|
@@ -792,7 +789,9 @@ function esbuildSveltePlugin(options) {
|
|
|
792
789
|
return {
|
|
793
790
|
name: "vite-plugin-svelte:optimize-svelte",
|
|
794
791
|
setup(build) {
|
|
795
|
-
|
|
792
|
+
var _a;
|
|
793
|
+
if ((_a = build.initialOptions.plugins) == null ? void 0 : _a.some((v) => v.name === "vite:dep-scan"))
|
|
794
|
+
return;
|
|
796
795
|
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
|
|
797
796
|
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
|
|
798
797
|
build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => {
|
|
@@ -807,23 +806,6 @@ function esbuildSveltePlugin(options) {
|
|
|
807
806
|
}
|
|
808
807
|
};
|
|
809
808
|
}
|
|
810
|
-
function disableVitePrebundleSvelte(build) {
|
|
811
|
-
var _a;
|
|
812
|
-
const viteDepPrebundlePlugin = (_a = build.initialOptions.plugins) == null ? void 0 : _a.find((v) => v.name === "vite:dep-pre-bundle");
|
|
813
|
-
if (!viteDepPrebundlePlugin)
|
|
814
|
-
return;
|
|
815
|
-
const _setup = viteDepPrebundlePlugin.setup.bind(viteDepPrebundlePlugin);
|
|
816
|
-
viteDepPrebundlePlugin.setup = function(build2) {
|
|
817
|
-
const _onResolve = build2.onResolve.bind(build2);
|
|
818
|
-
build2.onResolve = function(options, callback) {
|
|
819
|
-
if (options.filter.source.includes("svelte")) {
|
|
820
|
-
options.filter = new RegExp(options.filter.source.replace("|svelte", ""), options.filter.flags);
|
|
821
|
-
}
|
|
822
|
-
return _onResolve(options, callback);
|
|
823
|
-
};
|
|
824
|
-
return _setup(build2);
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
809
|
async function compileSvelte(options, { filename, code }) {
|
|
828
810
|
var _a, _b;
|
|
829
811
|
const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
|
|
@@ -909,6 +891,7 @@ async function buildSourceMap(from, to, filename) {
|
|
|
909
891
|
}
|
|
910
892
|
|
|
911
893
|
// src/utils/preprocess.ts
|
|
894
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
912
895
|
var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss"];
|
|
913
896
|
var supportedScriptLangs = ["ts"];
|
|
914
897
|
function createViteScriptPreprocessor() {
|
|
@@ -949,7 +932,7 @@ function createViteStylePreprocessor(config) {
|
|
|
949
932
|
const moduleId = `${filename}.${lang}`;
|
|
950
933
|
const transformResult = await pluginTransform(content, moduleId);
|
|
951
934
|
if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
|
|
952
|
-
transformResult.map.sources[0] = filename;
|
|
935
|
+
transformResult.map.sources[0] = import_path3.default.basename(filename);
|
|
953
936
|
}
|
|
954
937
|
return {
|
|
955
938
|
code: transformResult.code,
|
|
@@ -974,7 +957,10 @@ function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
|
974
957
|
s.append(" *{}");
|
|
975
958
|
return {
|
|
976
959
|
code: s.toString(),
|
|
977
|
-
map: s.generateDecodedMap({
|
|
960
|
+
map: s.generateDecodedMap({
|
|
961
|
+
source: filename ? import_path3.default.basename(filename) : void 0,
|
|
962
|
+
hires: true
|
|
963
|
+
})
|
|
978
964
|
};
|
|
979
965
|
}
|
|
980
966
|
};
|
|
@@ -1192,9 +1178,9 @@ function enforceOptionsForProduction(options) {
|
|
|
1192
1178
|
}
|
|
1193
1179
|
}
|
|
1194
1180
|
function resolveViteRoot(viteConfig) {
|
|
1195
|
-
return (0, import_vite3.normalizePath)(viteConfig.root ?
|
|
1181
|
+
return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
|
|
1196
1182
|
}
|
|
1197
|
-
function buildExtraViteConfig(options, config
|
|
1183
|
+
function buildExtraViteConfig(options, config) {
|
|
1198
1184
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1199
1185
|
const extraViteConfig = {
|
|
1200
1186
|
resolve: {
|
|
@@ -1202,22 +1188,31 @@ function buildExtraViteConfig(options, config, configEnv) {
|
|
|
1202
1188
|
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
|
|
1203
1189
|
}
|
|
1204
1190
|
};
|
|
1205
|
-
if (
|
|
1191
|
+
if (options.isServe) {
|
|
1206
1192
|
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
|
|
1207
1193
|
}
|
|
1208
|
-
|
|
1194
|
+
if (options.experimental.prebundleSvelteLibraries) {
|
|
1195
|
+
extraViteConfig.optimizeDeps = __spreadProps(__spreadValues({}, extraViteConfig.optimizeDeps), {
|
|
1196
|
+
extensions: options.extensions ?? [".svelte"],
|
|
1197
|
+
esbuildOptions: {
|
|
1198
|
+
plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {
|
|
1199
|
+
} }]
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1209
1204
|
return extraViteConfig;
|
|
1210
1205
|
}
|
|
1211
|
-
function buildOptimizeDepsForSvelte(svelteDeps, options,
|
|
1206
|
+
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1212
1207
|
const include = [];
|
|
1213
1208
|
const exclude = ["svelte-hmr"];
|
|
1214
1209
|
const isIncluded = (dep) => {
|
|
1215
1210
|
var _a;
|
|
1216
|
-
return include.includes(dep) || ((_a =
|
|
1211
|
+
return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
|
|
1217
1212
|
};
|
|
1218
1213
|
const isExcluded = (dep) => {
|
|
1219
1214
|
var _a;
|
|
1220
|
-
return exclude.includes(dep) || ((_a =
|
|
1215
|
+
return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1221
1216
|
};
|
|
1222
1217
|
if (!isExcluded("svelte")) {
|
|
1223
1218
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1227,14 +1222,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps2) {
|
|
|
1227
1222
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1228
1223
|
}
|
|
1229
1224
|
if (options.experimental.prebundleSvelteLibraries) {
|
|
1230
|
-
return {
|
|
1231
|
-
include,
|
|
1232
|
-
exclude,
|
|
1233
|
-
esbuildOptions: {
|
|
1234
|
-
plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {
|
|
1235
|
-
} }]
|
|
1236
|
-
}
|
|
1237
|
-
};
|
|
1225
|
+
return { include, exclude };
|
|
1238
1226
|
}
|
|
1239
1227
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
1240
1228
|
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter((dep) => !isIncluded(dep));
|
|
@@ -1268,9 +1256,16 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1268
1256
|
var _a2, _b2, _c2, _d;
|
|
1269
1257
|
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x)) && !((_d = (_c2 = config.optimizeDeps) == null ? void 0 : _c2.include) == null ? void 0 : _d.includes(x));
|
|
1270
1258
|
}));
|
|
1271
|
-
|
|
1259
|
+
const ssr = {
|
|
1272
1260
|
noExternal
|
|
1273
1261
|
};
|
|
1262
|
+
if (options.isServe) {
|
|
1263
|
+
ssr.external = Array.from(new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))).filter((dep) => {
|
|
1264
|
+
var _a2, _b2, _c2, _d;
|
|
1265
|
+
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.noExternal) == null ? void 0 : _b2.includes(dep)) && !((_d = (_c2 = config.ssr) == null ? void 0 : _c2.external) == null ? void 0 : _d.includes(dep));
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
return ssr;
|
|
1274
1269
|
}
|
|
1275
1270
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1276
1271
|
var _a, _b;
|
|
@@ -1349,8 +1344,8 @@ var VitePluginSvelteCache = class {
|
|
|
1349
1344
|
return this._js.get(svelteRequest.normalizedFilename);
|
|
1350
1345
|
}
|
|
1351
1346
|
}
|
|
1352
|
-
getDependants(
|
|
1353
|
-
const dependants = this._dependants.get(
|
|
1347
|
+
getDependants(path8) {
|
|
1348
|
+
const dependants = this._dependants.get(path8);
|
|
1354
1349
|
return dependants ? [...dependants] : [];
|
|
1355
1350
|
}
|
|
1356
1351
|
getResolvedSvelteField(name, importer) {
|
|
@@ -1366,7 +1361,7 @@ var VitePluginSvelteCache = class {
|
|
|
1366
1361
|
|
|
1367
1362
|
// src/utils/watch.ts
|
|
1368
1363
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
1369
|
-
var
|
|
1364
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
1370
1365
|
function setupWatchers(options, cache, requestParser) {
|
|
1371
1366
|
const { server, configFile: svelteConfigFile } = options;
|
|
1372
1367
|
if (!server) {
|
|
@@ -1405,7 +1400,7 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1405
1400
|
server.restart();
|
|
1406
1401
|
}
|
|
1407
1402
|
};
|
|
1408
|
-
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) =>
|
|
1403
|
+
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
|
|
1409
1404
|
const restartOnConfigAdd = (filename) => {
|
|
1410
1405
|
if (possibleSvelteConfigs.includes(filename)) {
|
|
1411
1406
|
triggerViteRestart(filename);
|
|
@@ -1435,12 +1430,12 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1435
1430
|
}
|
|
1436
1431
|
function ensureWatchedFile(watcher, file, root) {
|
|
1437
1432
|
if (file && !file.startsWith(root + "/") && !file.includes("\0") && import_fs4.default.existsSync(file)) {
|
|
1438
|
-
watcher.add(
|
|
1433
|
+
watcher.add(import_path5.default.resolve(file));
|
|
1439
1434
|
}
|
|
1440
1435
|
}
|
|
1441
1436
|
|
|
1442
1437
|
// src/utils/resolve.ts
|
|
1443
|
-
var
|
|
1438
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
1444
1439
|
var import_module4 = require("module");
|
|
1445
1440
|
function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
1446
1441
|
if (importer && isBareImport(importee) && !isNodeInternal(importee) && !is_common_without_svelte_field(importee)) {
|
|
@@ -1453,7 +1448,7 @@ function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
|
1453
1448
|
if (pkgData) {
|
|
1454
1449
|
const { pkg, dir } = pkgData;
|
|
1455
1450
|
if (pkg.svelte) {
|
|
1456
|
-
const result =
|
|
1451
|
+
const result = import_path6.default.resolve(dir, pkg.svelte);
|
|
1457
1452
|
cache.setResolvedSvelteField(importee, importer, result);
|
|
1458
1453
|
return result;
|
|
1459
1454
|
}
|
|
@@ -1464,7 +1459,7 @@ function isNodeInternal(importee) {
|
|
|
1464
1459
|
return importee.startsWith("node:") || import_module4.builtinModules.includes(importee);
|
|
1465
1460
|
}
|
|
1466
1461
|
function isBareImport(importee) {
|
|
1467
|
-
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") ||
|
|
1462
|
+
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path6.default.isAbsolute(importee)) {
|
|
1468
1463
|
return false;
|
|
1469
1464
|
}
|
|
1470
1465
|
const parts = importee.split("/");
|
|
@@ -1479,9 +1474,8 @@ function isBareImport(importee) {
|
|
|
1479
1474
|
}
|
|
1480
1475
|
|
|
1481
1476
|
// src/utils/optimizer.ts
|
|
1482
|
-
var import_fs5 =
|
|
1483
|
-
var
|
|
1484
|
-
var import_vite4 = require("vite");
|
|
1477
|
+
var import_fs5 = require("fs");
|
|
1478
|
+
var import_path7 = __toESM(require("path"), 1);
|
|
1485
1479
|
var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
1486
1480
|
"compilerOptions",
|
|
1487
1481
|
"configFile",
|
|
@@ -1490,23 +1484,20 @@ var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
|
1490
1484
|
"ignorePluginPreprocessors",
|
|
1491
1485
|
"preprocess"
|
|
1492
1486
|
];
|
|
1493
|
-
async function
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
const
|
|
1497
|
-
if (!viteMetadataPath)
|
|
1498
|
-
return;
|
|
1499
|
-
const svelteMetadataPath = import_path6.default.resolve(viteMetadataPath, "../_svelte_metadata.json");
|
|
1500
|
-
const currentSvelteMetadata = JSON.stringify(generateSvelteMetadata(options), (_, value) => {
|
|
1487
|
+
async function saveSvelteMetadata(cacheDir, options) {
|
|
1488
|
+
const svelteMetadata = generateSvelteMetadata(options);
|
|
1489
|
+
const svelteMetadataPath = import_path7.default.resolve(cacheDir, "_svelte_metadata.json");
|
|
1490
|
+
const currentSvelteMetadata = JSON.stringify(svelteMetadata, (_, value) => {
|
|
1501
1491
|
return typeof value === "function" ? value.toString() : value;
|
|
1502
1492
|
});
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1493
|
+
let existingSvelteMetadata;
|
|
1494
|
+
try {
|
|
1495
|
+
existingSvelteMetadata = await import_fs5.promises.readFile(svelteMetadataPath, "utf8");
|
|
1496
|
+
} catch {
|
|
1507
1497
|
}
|
|
1508
|
-
await
|
|
1509
|
-
import_fs5.
|
|
1498
|
+
await import_fs5.promises.mkdir(cacheDir, { recursive: true });
|
|
1499
|
+
await import_fs5.promises.writeFile(svelteMetadataPath, currentSvelteMetadata);
|
|
1500
|
+
return currentSvelteMetadata !== existingSvelteMetadata;
|
|
1510
1501
|
}
|
|
1511
1502
|
function generateSvelteMetadata(options) {
|
|
1512
1503
|
const metadata = {};
|
|
@@ -1515,14 +1506,6 @@ function generateSvelteMetadata(options) {
|
|
|
1515
1506
|
}
|
|
1516
1507
|
return metadata;
|
|
1517
1508
|
}
|
|
1518
|
-
function findViteMetadataPath(cacheDir) {
|
|
1519
|
-
const metadataPaths = ["_metadata.json", "deps/_metadata.json"];
|
|
1520
|
-
for (const metadataPath of metadataPaths) {
|
|
1521
|
-
const viteMetadataPath = import_path6.default.resolve(cacheDir, metadataPath);
|
|
1522
|
-
if (import_fs5.default.existsSync(viteMetadataPath))
|
|
1523
|
-
return viteMetadataPath;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
1509
|
|
|
1527
1510
|
// src/index.ts
|
|
1528
1511
|
function svelte(inlineOptions) {
|
|
@@ -1546,7 +1529,7 @@ function svelte(inlineOptions) {
|
|
|
1546
1529
|
log.setLevel(config.logLevel);
|
|
1547
1530
|
}
|
|
1548
1531
|
options = await preResolveOptions(inlineOptions, config, configEnv);
|
|
1549
|
-
const extraViteConfig = buildExtraViteConfig(options, config
|
|
1532
|
+
const extraViteConfig = buildExtraViteConfig(options, config);
|
|
1550
1533
|
log.debug("additional vite config", extraViteConfig);
|
|
1551
1534
|
return extraViteConfig;
|
|
1552
1535
|
},
|
|
@@ -1559,7 +1542,12 @@ function svelte(inlineOptions) {
|
|
|
1559
1542
|
log.debug("resolved options", options);
|
|
1560
1543
|
},
|
|
1561
1544
|
async buildStart() {
|
|
1562
|
-
|
|
1545
|
+
if (!options.experimental.prebundleSvelteLibraries)
|
|
1546
|
+
return;
|
|
1547
|
+
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1548
|
+
if (isSvelteMetadataChanged) {
|
|
1549
|
+
viteConfig.server.force = true;
|
|
1550
|
+
}
|
|
1563
1551
|
},
|
|
1564
1552
|
configureServer(server) {
|
|
1565
1553
|
options.server = server;
|
|
@@ -1650,7 +1638,6 @@ function svelte(inlineOptions) {
|
|
|
1650
1638
|
}
|
|
1651
1639
|
};
|
|
1652
1640
|
}
|
|
1653
|
-
module.exports = __toCommonJS(src_exports);
|
|
1654
1641
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1655
1642
|
0 && (module.exports = {
|
|
1656
1643
|
svelte
|