@sveltejs/vite-plugin-svelte 1.0.8 → 1.1.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 +32 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -12
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/index.ts +1 -1
- package/src/utils/id.ts +1 -1
- package/src/utils/options.ts +20 -9
- package/src/utils/preprocess.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,7 @@ __export(src_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(src_exports);
|
|
33
33
|
|
|
34
|
-
// ../../node_modules/.pnpm/tsup@6.
|
|
34
|
+
// ../../node_modules/.pnpm/tsup@6.3.0/node_modules/tsup/assets/cjs_shims.js
|
|
35
35
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
36
36
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
37
37
|
|
|
@@ -415,8 +415,8 @@ function createCompileSvelte(options) {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
// src/utils/id.ts
|
|
418
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
419
418
|
var import_vite = require("vite");
|
|
419
|
+
var import_vite2 = require("vite");
|
|
420
420
|
var fs = __toESM(require("fs"), 1);
|
|
421
421
|
var VITE_FS_PREFIX = "/@fs/";
|
|
422
422
|
var IS_WINDOWS = process.platform === "win32";
|
|
@@ -465,7 +465,7 @@ function parseRequestQuery(rawQuery) {
|
|
|
465
465
|
return query;
|
|
466
466
|
}
|
|
467
467
|
function normalize(filename, normalizedRoot) {
|
|
468
|
-
return stripRoot((0,
|
|
468
|
+
return stripRoot((0, import_vite2.normalizePath)(filename), normalizedRoot);
|
|
469
469
|
}
|
|
470
470
|
function existsInRoot(filename, root) {
|
|
471
471
|
if (filename.startsWith(VITE_FS_PREFIX)) {
|
|
@@ -477,12 +477,12 @@ function stripRoot(normalizedFilename, normalizedRoot) {
|
|
|
477
477
|
return normalizedFilename.startsWith(normalizedRoot + "/") ? normalizedFilename.slice(normalizedRoot.length) : normalizedFilename;
|
|
478
478
|
}
|
|
479
479
|
function buildFilter(include, exclude, extensions) {
|
|
480
|
-
const rollupFilter = (0,
|
|
480
|
+
const rollupFilter = (0, import_vite.createFilter)(include, exclude);
|
|
481
481
|
return (filename) => rollupFilter(filename) && extensions.some((ext) => filename.endsWith(ext));
|
|
482
482
|
}
|
|
483
483
|
function buildIdParser(options) {
|
|
484
484
|
const { include, exclude, extensions, root } = options;
|
|
485
|
-
const normalizedRoot = (0,
|
|
485
|
+
const normalizedRoot = (0, import_vite2.normalizePath)(root);
|
|
486
486
|
const filter = buildFilter(include, exclude, extensions);
|
|
487
487
|
return (id, ssr, timestamp = Date.now()) => {
|
|
488
488
|
const { filename, rawQuery } = splitId(id);
|
|
@@ -493,7 +493,7 @@ function buildIdParser(options) {
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
// src/utils/options.ts
|
|
496
|
-
var
|
|
496
|
+
var import_vite4 = require("vite");
|
|
497
497
|
|
|
498
498
|
// src/utils/load-svelte-config.ts
|
|
499
499
|
var import_module = require("module");
|
|
@@ -897,7 +897,7 @@ async function compileSvelte(options, { filename, code }) {
|
|
|
897
897
|
}
|
|
898
898
|
|
|
899
899
|
// src/utils/preprocess.ts
|
|
900
|
-
var
|
|
900
|
+
var import_vite3 = require("vite");
|
|
901
901
|
var import_magic_string2 = __toESM(require("magic-string"), 1);
|
|
902
902
|
var import_compiler3 = require("svelte/compiler");
|
|
903
903
|
|
|
@@ -958,8 +958,9 @@ function createViteScriptPreprocessor() {
|
|
|
958
958
|
const lang = attributes.lang;
|
|
959
959
|
if (!supportedScriptLangs.includes(lang))
|
|
960
960
|
return;
|
|
961
|
-
const transformResult = await (0,
|
|
961
|
+
const transformResult = await (0, import_vite3.transformWithEsbuild)(content, filename, {
|
|
962
962
|
loader: lang,
|
|
963
|
+
target: "esnext",
|
|
963
964
|
tsconfigRaw: {
|
|
964
965
|
compilerOptions: {
|
|
965
966
|
importsNotUsedAsValues: "preserve",
|
|
@@ -1161,6 +1162,7 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
|
1161
1162
|
"hot",
|
|
1162
1163
|
"ignorePluginPreprocessors",
|
|
1163
1164
|
"disableDependencyReinclusion",
|
|
1165
|
+
"prebundleSvelteLibraries",
|
|
1164
1166
|
"experimental"
|
|
1165
1167
|
]);
|
|
1166
1168
|
var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
|
|
@@ -1287,6 +1289,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1287
1289
|
};
|
|
1288
1290
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1289
1291
|
removeIgnoredOptions(merged);
|
|
1292
|
+
handleDeprecatedOptions(merged);
|
|
1290
1293
|
addSvelteKitOptions(merged);
|
|
1291
1294
|
addExtraPreprocessors(merged, viteConfig);
|
|
1292
1295
|
enforceOptionsForHmr(merged);
|
|
@@ -1376,11 +1379,20 @@ function addSvelteKitOptions(options) {
|
|
|
1376
1379
|
options.compilerOptions.hydratable = hydratable;
|
|
1377
1380
|
}
|
|
1378
1381
|
}
|
|
1382
|
+
function handleDeprecatedOptions(options) {
|
|
1383
|
+
var _a, _b;
|
|
1384
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1385
|
+
options.prebundleSvelteLibraries = (_b = options.experimental) == null ? void 0 : _b.prebundleSvelteLibraries;
|
|
1386
|
+
log.warn(
|
|
1387
|
+
"experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1379
1391
|
function resolveViteRoot(viteConfig) {
|
|
1380
|
-
return (0,
|
|
1392
|
+
return (0, import_vite4.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
|
|
1381
1393
|
}
|
|
1382
1394
|
function buildExtraViteConfig(options, config) {
|
|
1383
|
-
var _a
|
|
1395
|
+
var _a;
|
|
1384
1396
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1385
1397
|
const extraViteConfig = {
|
|
1386
1398
|
resolve: {
|
|
@@ -1393,7 +1405,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1393
1405
|
options,
|
|
1394
1406
|
config.optimizeDeps
|
|
1395
1407
|
);
|
|
1396
|
-
if (
|
|
1408
|
+
if (options.prebundleSvelteLibraries) {
|
|
1397
1409
|
extraViteConfig.optimizeDeps = {
|
|
1398
1410
|
...extraViteConfig.optimizeDeps,
|
|
1399
1411
|
extensions: options.extensions ?? [".svelte"],
|
|
@@ -1404,23 +1416,22 @@ function buildExtraViteConfig(options, config) {
|
|
|
1404
1416
|
};
|
|
1405
1417
|
}
|
|
1406
1418
|
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1407
|
-
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((
|
|
1419
|
+
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((_a = config.experimental) == null ? void 0 : _a.hmrPartialAccept) !== false) {
|
|
1408
1420
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1409
1421
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1410
1422
|
}
|
|
1411
1423
|
return extraViteConfig;
|
|
1412
1424
|
}
|
|
1413
1425
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1414
|
-
var _a;
|
|
1415
1426
|
const include = [];
|
|
1416
1427
|
const exclude = ["svelte-hmr"];
|
|
1417
1428
|
const isIncluded = (dep) => {
|
|
1418
|
-
var
|
|
1419
|
-
return include.includes(dep) || ((
|
|
1429
|
+
var _a;
|
|
1430
|
+
return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
|
|
1420
1431
|
};
|
|
1421
1432
|
const isExcluded = (dep) => {
|
|
1422
|
-
var
|
|
1423
|
-
return exclude.includes(dep) || ((
|
|
1433
|
+
var _a;
|
|
1434
|
+
return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1424
1435
|
};
|
|
1425
1436
|
if (!isExcluded("svelte")) {
|
|
1426
1437
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1431,7 +1442,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1431
1442
|
} else {
|
|
1432
1443
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1433
1444
|
}
|
|
1434
|
-
if (
|
|
1445
|
+
if (options.prebundleSvelteLibraries) {
|
|
1435
1446
|
return { include, exclude };
|
|
1436
1447
|
}
|
|
1437
1448
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1755,7 +1766,7 @@ function generateSvelteMetadata(options) {
|
|
|
1755
1766
|
}
|
|
1756
1767
|
|
|
1757
1768
|
// src/ui/inspector/plugin.ts
|
|
1758
|
-
var
|
|
1769
|
+
var import_vite5 = require("vite");
|
|
1759
1770
|
var import_path8 = __toESM(require("path"), 1);
|
|
1760
1771
|
var import_url2 = require("url");
|
|
1761
1772
|
var import_fs6 = __toESM(require("fs"), 1);
|
|
@@ -1783,7 +1794,7 @@ var defaultInspectorOptions = {
|
|
|
1783
1794
|
customStyles: true
|
|
1784
1795
|
};
|
|
1785
1796
|
function getInspectorPath() {
|
|
1786
|
-
const pluginPath = (0,
|
|
1797
|
+
const pluginPath = (0, import_vite5.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
|
|
1787
1798
|
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1788
1799
|
}
|
|
1789
1800
|
function svelteInspector() {
|
|
@@ -1912,8 +1923,7 @@ function svelte(inlineOptions) {
|
|
|
1912
1923
|
log.debug("resolved options", options);
|
|
1913
1924
|
},
|
|
1914
1925
|
async buildStart() {
|
|
1915
|
-
|
|
1916
|
-
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1926
|
+
if (!options.prebundleSvelteLibraries)
|
|
1917
1927
|
return;
|
|
1918
1928
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1919
1929
|
if (isSvelteMetadataChanged) {
|