@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.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/";
|
|
@@ -935,6 +935,7 @@ function createViteScriptPreprocessor() {
|
|
|
935
935
|
return;
|
|
936
936
|
const transformResult = await transformWithEsbuild(content, filename, {
|
|
937
937
|
loader: lang,
|
|
938
|
+
target: "esnext",
|
|
938
939
|
tsconfigRaw: {
|
|
939
940
|
compilerOptions: {
|
|
940
941
|
importsNotUsedAsValues: "preserve",
|
|
@@ -1136,6 +1137,7 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
|
1136
1137
|
"hot",
|
|
1137
1138
|
"ignorePluginPreprocessors",
|
|
1138
1139
|
"disableDependencyReinclusion",
|
|
1140
|
+
"prebundleSvelteLibraries",
|
|
1139
1141
|
"experimental"
|
|
1140
1142
|
]);
|
|
1141
1143
|
var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
|
|
@@ -1262,6 +1264,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1262
1264
|
};
|
|
1263
1265
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1264
1266
|
removeIgnoredOptions(merged);
|
|
1267
|
+
handleDeprecatedOptions(merged);
|
|
1265
1268
|
addSvelteKitOptions(merged);
|
|
1266
1269
|
addExtraPreprocessors(merged, viteConfig);
|
|
1267
1270
|
enforceOptionsForHmr(merged);
|
|
@@ -1351,11 +1354,20 @@ function addSvelteKitOptions(options) {
|
|
|
1351
1354
|
options.compilerOptions.hydratable = hydratable;
|
|
1352
1355
|
}
|
|
1353
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
|
+
}
|
|
1354
1366
|
function resolveViteRoot(viteConfig) {
|
|
1355
1367
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1356
1368
|
}
|
|
1357
1369
|
function buildExtraViteConfig(options, config) {
|
|
1358
|
-
var _a
|
|
1370
|
+
var _a;
|
|
1359
1371
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1360
1372
|
const extraViteConfig = {
|
|
1361
1373
|
resolve: {
|
|
@@ -1368,7 +1380,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1368
1380
|
options,
|
|
1369
1381
|
config.optimizeDeps
|
|
1370
1382
|
);
|
|
1371
|
-
if (
|
|
1383
|
+
if (options.prebundleSvelteLibraries) {
|
|
1372
1384
|
extraViteConfig.optimizeDeps = {
|
|
1373
1385
|
...extraViteConfig.optimizeDeps,
|
|
1374
1386
|
extensions: options.extensions ?? [".svelte"],
|
|
@@ -1379,23 +1391,22 @@ function buildExtraViteConfig(options, config) {
|
|
|
1379
1391
|
};
|
|
1380
1392
|
}
|
|
1381
1393
|
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
|
|
1382
|
-
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) {
|
|
1383
1395
|
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
1384
1396
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
1385
1397
|
}
|
|
1386
1398
|
return extraViteConfig;
|
|
1387
1399
|
}
|
|
1388
1400
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1389
|
-
var _a;
|
|
1390
1401
|
const include = [];
|
|
1391
1402
|
const exclude = ["svelte-hmr"];
|
|
1392
1403
|
const isIncluded = (dep) => {
|
|
1393
|
-
var
|
|
1394
|
-
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));
|
|
1395
1406
|
};
|
|
1396
1407
|
const isExcluded = (dep) => {
|
|
1397
|
-
var
|
|
1398
|
-
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}/`)));
|
|
1399
1410
|
};
|
|
1400
1411
|
if (!isExcluded("svelte")) {
|
|
1401
1412
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1406,7 +1417,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1406
1417
|
} else {
|
|
1407
1418
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1408
1419
|
}
|
|
1409
|
-
if (
|
|
1420
|
+
if (options.prebundleSvelteLibraries) {
|
|
1410
1421
|
return { include, exclude };
|
|
1411
1422
|
}
|
|
1412
1423
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1887,8 +1898,7 @@ function svelte(inlineOptions) {
|
|
|
1887
1898
|
log.debug("resolved options", options);
|
|
1888
1899
|
},
|
|
1889
1900
|
async buildStart() {
|
|
1890
|
-
|
|
1891
|
-
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1901
|
+
if (!options.prebundleSvelteLibraries)
|
|
1892
1902
|
return;
|
|
1893
1903
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1894
1904
|
if (isSvelteMetadataChanged) {
|