@sveltejs/vite-plugin-svelte 1.0.9 → 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 +31 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +1 -1
- package/src/utils/id.ts +1 -1
- package/src/utils/options.ts +20 -9
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,12 @@ interface PluginOptions {
|
|
|
77
77
|
* @default false
|
|
78
78
|
*/
|
|
79
79
|
disableDependencyReinclusion?: boolean | string[];
|
|
80
|
+
/**
|
|
81
|
+
* Force Vite to pre-bundle Svelte libraries
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
prebundleSvelteLibraries?: boolean;
|
|
80
86
|
/**
|
|
81
87
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
82
88
|
*/
|
|
@@ -124,12 +130,6 @@ interface ExperimentalOptions {
|
|
|
124
130
|
* @default false
|
|
125
131
|
*/
|
|
126
132
|
useVitePreprocess?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Force Vite to pre-bundle Svelte libraries
|
|
129
|
-
*
|
|
130
|
-
* @default false
|
|
131
|
-
*/
|
|
132
|
-
prebundleSvelteLibraries?: boolean;
|
|
133
133
|
/**
|
|
134
134
|
* If a preprocessor does not provide a sourcemap, a best-effort fallback sourcemap will be provided.
|
|
135
135
|
* This option requires `diff-match-patch` to be installed as a peer dependency.
|
package/dist/index.js
CHANGED
|
@@ -386,7 +386,7 @@ function createCompileSvelte(options) {
|
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
// src/utils/id.ts
|
|
389
|
-
import { createFilter } from "
|
|
389
|
+
import { createFilter } from "vite";
|
|
390
390
|
import { normalizePath } from "vite";
|
|
391
391
|
import * as fs from "fs";
|
|
392
392
|
var VITE_FS_PREFIX = "/@fs/";
|
|
@@ -1137,6 +1137,7 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
|
1137
1137
|
"hot",
|
|
1138
1138
|
"ignorePluginPreprocessors",
|
|
1139
1139
|
"disableDependencyReinclusion",
|
|
1140
|
+
"prebundleSvelteLibraries",
|
|
1140
1141
|
"experimental"
|
|
1141
1142
|
]);
|
|
1142
1143
|
var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
|
|
@@ -1263,6 +1264,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1263
1264
|
};
|
|
1264
1265
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1265
1266
|
removeIgnoredOptions(merged);
|
|
1267
|
+
handleDeprecatedOptions(merged);
|
|
1266
1268
|
addSvelteKitOptions(merged);
|
|
1267
1269
|
addExtraPreprocessors(merged, viteConfig);
|
|
1268
1270
|
enforceOptionsForHmr(merged);
|
|
@@ -1352,11 +1354,20 @@ function addSvelteKitOptions(options) {
|
|
|
1352
1354
|
options.compilerOptions.hydratable = hydratable;
|
|
1353
1355
|
}
|
|
1354
1356
|
}
|
|
1357
|
+
function handleDeprecatedOptions(options) {
|
|
1358
|
+
var _a, _b;
|
|
1359
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1360
|
+
options.prebundleSvelteLibraries = (_b = options.experimental) == null ? void 0 : _b.prebundleSvelteLibraries;
|
|
1361
|
+
log.warn(
|
|
1362
|
+
"experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1355
1366
|
function resolveViteRoot(viteConfig) {
|
|
1356
1367
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1357
1368
|
}
|
|
1358
1369
|
function buildExtraViteConfig(options, config) {
|
|
1359
|
-
var _a
|
|
1370
|
+
var _a;
|
|
1360
1371
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1361
1372
|
const extraViteConfig = {
|
|
1362
1373
|
resolve: {
|
|
@@ -1369,7 +1380,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1369
1380
|
options,
|
|
1370
1381
|
config.optimizeDeps
|
|
1371
1382
|
);
|
|
1372
|
-
if (
|
|
1383
|
+
if (options.prebundleSvelteLibraries) {
|
|
1373
1384
|
extraViteConfig.optimizeDeps = {
|
|
1374
1385
|
...extraViteConfig.optimizeDeps,
|
|
1375
1386
|
extensions: options.extensions ?? [".svelte"],
|
|
@@ -1380,23 +1391,22 @@ function buildExtraViteConfig(options, config) {
|
|
|
1380
1391
|
};
|
|
1381
1392
|
}
|
|
1382
1393
|
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1383
|
-
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((
|
|
1394
|
+
if ((options.hot == null || options.hot === true || options.hot && options.hot.partialAccept !== false) && ((_a = config.experimental) == null ? void 0 : _a.hmrPartialAccept) !== false) {
|
|
1384
1395
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1385
1396
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1386
1397
|
}
|
|
1387
1398
|
return extraViteConfig;
|
|
1388
1399
|
}
|
|
1389
1400
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1390
|
-
var _a;
|
|
1391
1401
|
const include = [];
|
|
1392
1402
|
const exclude = ["svelte-hmr"];
|
|
1393
1403
|
const isIncluded = (dep) => {
|
|
1394
|
-
var
|
|
1395
|
-
return include.includes(dep) || ((
|
|
1404
|
+
var _a;
|
|
1405
|
+
return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
|
|
1396
1406
|
};
|
|
1397
1407
|
const isExcluded = (dep) => {
|
|
1398
|
-
var
|
|
1399
|
-
return exclude.includes(dep) || ((
|
|
1408
|
+
var _a;
|
|
1409
|
+
return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1400
1410
|
};
|
|
1401
1411
|
if (!isExcluded("svelte")) {
|
|
1402
1412
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1407,7 +1417,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1407
1417
|
} else {
|
|
1408
1418
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1409
1419
|
}
|
|
1410
|
-
if (
|
|
1420
|
+
if (options.prebundleSvelteLibraries) {
|
|
1411
1421
|
return { include, exclude };
|
|
1412
1422
|
}
|
|
1413
1423
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1888,8 +1898,7 @@ function svelte(inlineOptions) {
|
|
|
1888
1898
|
log.debug("resolved options", options);
|
|
1889
1899
|
},
|
|
1890
1900
|
async buildStart() {
|
|
1891
|
-
|
|
1892
|
-
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1901
|
+
if (!options.prebundleSvelteLibraries)
|
|
1893
1902
|
return;
|
|
1894
1903
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1895
1904
|
if (isSvelteMetadataChanged) {
|