@sveltejs/vite-plugin-svelte 1.0.0-next.42 → 1.0.0-next.43
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 +259 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -2
- package/dist/index.js +259 -140
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/index.ts +162 -135
- package/src/ui/inspector/Inspector.svelte +229 -0
- package/src/ui/inspector/icon.svg +5 -0
- package/src/ui/inspector/load-inspector.ts +16 -0
- package/src/ui/inspector/plugin.ts +101 -0
- package/src/utils/compile.ts +4 -0
- package/src/utils/options.ts +77 -26
- package/src/utils/watch.ts +22 -18
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface Options {
|
|
|
8
8
|
/**
|
|
9
9
|
* Path to a svelte config file, either absolute or relative to Vite root
|
|
10
10
|
*
|
|
11
|
-
* set to `false` to
|
|
11
|
+
* set to `false` to ignore the svelte config file
|
|
12
12
|
*
|
|
13
13
|
* @see https://vitejs.dev/config/#root
|
|
14
14
|
*/
|
|
@@ -150,11 +150,54 @@ interface ExperimentalOptions {
|
|
|
150
150
|
code: string;
|
|
151
151
|
compileOptions: Partial<CompileOptions>;
|
|
152
152
|
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
153
|
+
/**
|
|
154
|
+
* enable svelte inspector
|
|
155
|
+
*/
|
|
156
|
+
inspector?: InspectorOptions | boolean;
|
|
157
|
+
}
|
|
158
|
+
interface InspectorOptions {
|
|
159
|
+
/**
|
|
160
|
+
* define a key combo to toggle inspector,
|
|
161
|
+
* @default 'control-shift' on windows, 'meta-shift' on other os
|
|
162
|
+
*
|
|
163
|
+
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
|
|
164
|
+
* examples: control-shift, control-o, control-alt-s meta-x control-meta
|
|
165
|
+
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
|
|
166
|
+
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
|
|
167
|
+
*/
|
|
168
|
+
toggleKeyCombo?: string;
|
|
169
|
+
/**
|
|
170
|
+
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
|
|
171
|
+
* @default false
|
|
172
|
+
*/
|
|
173
|
+
holdMode?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* when to show the toggle button
|
|
176
|
+
* @default 'active'
|
|
177
|
+
*/
|
|
178
|
+
showToggleButton?: 'always' | 'active' | 'never';
|
|
179
|
+
/**
|
|
180
|
+
* where to display the toggle button
|
|
181
|
+
* @default top-right
|
|
182
|
+
*/
|
|
183
|
+
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
184
|
+
/**
|
|
185
|
+
* inject custom styles when inspector is active
|
|
186
|
+
*/
|
|
187
|
+
customStyles?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* append an import to the module id ending with `appendTo` instead of adding a script into body
|
|
190
|
+
* useful for frameworks that do not support trannsformIndexHtml hook
|
|
191
|
+
*
|
|
192
|
+
* WARNING: only set this if you know exactly what it does.
|
|
193
|
+
* Regular users of vite-plugin-svelte or SvelteKit do not need it
|
|
194
|
+
*/
|
|
195
|
+
appendTo?: string;
|
|
153
196
|
}
|
|
154
197
|
declare type ModuleFormat = NonNullable<CompileOptions['format']>;
|
|
155
198
|
declare type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
156
199
|
declare type Arrayable<T> = T | T[];
|
|
157
200
|
|
|
158
|
-
declare function svelte(inlineOptions?: Partial<Options>): Plugin;
|
|
201
|
+
declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
|
|
159
202
|
|
|
160
203
|
export { Arrayable, CssHashGetter, ModuleFormat, Options, svelte };
|
package/dist/index.js
CHANGED
|
@@ -272,8 +272,9 @@ function toSafe(base64) {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
// src/utils/compile.ts
|
|
275
|
+
var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
275
276
|
var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
|
|
276
|
-
var _a, _b;
|
|
277
|
+
var _a, _b, _c;
|
|
277
278
|
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
|
|
278
279
|
const { emitCss = true } = options;
|
|
279
280
|
const dependencies = [];
|
|
@@ -336,6 +337,7 @@ import ${JSON.stringify(cssId)};
|
|
|
336
337
|
return {
|
|
337
338
|
filename,
|
|
338
339
|
normalizedFilename,
|
|
340
|
+
lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
|
|
339
341
|
compiled,
|
|
340
342
|
ssr,
|
|
341
343
|
dependencies
|
|
@@ -1053,6 +1055,7 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1053
1055
|
}
|
|
1054
1056
|
|
|
1055
1057
|
// src/utils/options.ts
|
|
1058
|
+
import deepmerge from "deepmerge";
|
|
1056
1059
|
var knownOptions = /* @__PURE__ */ new Set([
|
|
1057
1060
|
"configFile",
|
|
1058
1061
|
"include",
|
|
@@ -1065,7 +1068,8 @@ var knownOptions = /* @__PURE__ */ new Set([
|
|
|
1065
1068
|
"hot",
|
|
1066
1069
|
"ignorePluginPreprocessors",
|
|
1067
1070
|
"disableDependencyReinclusion",
|
|
1068
|
-
"experimental"
|
|
1071
|
+
"experimental",
|
|
1072
|
+
"kit"
|
|
1069
1073
|
]);
|
|
1070
1074
|
function validateInlineOptions(inlineOptions) {
|
|
1071
1075
|
const invalidKeys = Object.keys(inlineOptions || {}).filter((key) => !knownOptions.has(key));
|
|
@@ -1085,19 +1089,27 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1085
1089
|
}
|
|
1086
1090
|
};
|
|
1087
1091
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
|
|
1088
|
-
const
|
|
1089
|
-
compilerOptions: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.compilerOptions), svelteConfig == null ? void 0 : svelteConfig.compilerOptions), inlineOptions == null ? void 0 : inlineOptions.compilerOptions),
|
|
1090
|
-
experimental: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.experimental), svelteConfig == null ? void 0 : svelteConfig.experimental), inlineOptions == null ? void 0 : inlineOptions.experimental),
|
|
1092
|
+
const extraOptions = {
|
|
1091
1093
|
root: viteConfigWithResolvedRoot.root,
|
|
1092
1094
|
isBuild: viteEnv.command === "build",
|
|
1093
1095
|
isServe: viteEnv.command === "serve",
|
|
1094
1096
|
isDebug: process.env.DEBUG != null
|
|
1095
|
-
}
|
|
1097
|
+
};
|
|
1098
|
+
const merged = mergeConfigs(defaultOptions, svelteConfig, inlineOptions, extraOptions);
|
|
1096
1099
|
if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
|
|
1097
1100
|
merged.configFile = svelteConfig.configFile;
|
|
1098
1101
|
}
|
|
1099
1102
|
return merged;
|
|
1100
1103
|
}
|
|
1104
|
+
function mergeConfigs(...configs) {
|
|
1105
|
+
let result = {};
|
|
1106
|
+
for (const config of configs.filter(Boolean)) {
|
|
1107
|
+
result = deepmerge(result, config, {
|
|
1108
|
+
arrayMerge: (target, source) => source ?? target
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
return result;
|
|
1112
|
+
}
|
|
1101
1113
|
function resolveOptions(preResolveOptions2, viteConfig) {
|
|
1102
1114
|
const defaultOptions = {
|
|
1103
1115
|
hot: viteConfig.isProduction ? false : { injectCss: !preResolveOptions2.emitCss },
|
|
@@ -1106,11 +1118,11 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1106
1118
|
dev: !viteConfig.isProduction
|
|
1107
1119
|
}
|
|
1108
1120
|
};
|
|
1109
|
-
const
|
|
1110
|
-
compilerOptions: __spreadValues(__spreadValues({}, defaultOptions.compilerOptions), preResolveOptions2.compilerOptions),
|
|
1121
|
+
const extraOptions = {
|
|
1111
1122
|
root: viteConfig.root,
|
|
1112
1123
|
isProduction: viteConfig.isProduction
|
|
1113
|
-
}
|
|
1124
|
+
};
|
|
1125
|
+
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1114
1126
|
addExtraPreprocessors(merged, viteConfig);
|
|
1115
1127
|
enforceOptionsForHmr(merged);
|
|
1116
1128
|
enforceOptionsForProduction(merged);
|
|
@@ -1163,6 +1175,7 @@ function resolveViteRoot(viteConfig) {
|
|
|
1163
1175
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1164
1176
|
}
|
|
1165
1177
|
function buildExtraViteConfig(options, config) {
|
|
1178
|
+
var _a;
|
|
1166
1179
|
const svelteDeps = findRootSvelteDependencies(options.root);
|
|
1167
1180
|
const extraViteConfig = {
|
|
1168
1181
|
resolve: {
|
|
@@ -1173,7 +1186,7 @@ function buildExtraViteConfig(options, config) {
|
|
|
1173
1186
|
if (options.isServe) {
|
|
1174
1187
|
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
|
|
1175
1188
|
}
|
|
1176
|
-
if (options.experimental.prebundleSvelteLibraries) {
|
|
1189
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1177
1190
|
extraViteConfig.optimizeDeps = __spreadProps(__spreadValues({}, extraViteConfig.optimizeDeps), {
|
|
1178
1191
|
extensions: options.extensions ?? [".svelte"],
|
|
1179
1192
|
esbuildOptions: {
|
|
@@ -1186,15 +1199,16 @@ function buildExtraViteConfig(options, config) {
|
|
|
1186
1199
|
return extraViteConfig;
|
|
1187
1200
|
}
|
|
1188
1201
|
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
1202
|
+
var _a;
|
|
1189
1203
|
const include = [];
|
|
1190
1204
|
const exclude = ["svelte-hmr"];
|
|
1191
1205
|
const isIncluded = (dep) => {
|
|
1192
|
-
var
|
|
1193
|
-
return include.includes(dep) || ((
|
|
1206
|
+
var _a2;
|
|
1207
|
+
return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
|
|
1194
1208
|
};
|
|
1195
1209
|
const isExcluded = (dep) => {
|
|
1196
|
-
var
|
|
1197
|
-
return exclude.includes(dep) || ((
|
|
1210
|
+
var _a2;
|
|
1211
|
+
return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
|
|
1198
1212
|
};
|
|
1199
1213
|
if (!isExcluded("svelte")) {
|
|
1200
1214
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
@@ -1203,7 +1217,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1203
1217
|
} else {
|
|
1204
1218
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
1205
1219
|
}
|
|
1206
|
-
if (options.experimental.prebundleSvelteLibraries) {
|
|
1220
|
+
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1207
1221
|
return { include, exclude };
|
|
1208
1222
|
}
|
|
1209
1223
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
@@ -1382,27 +1396,29 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1382
1396
|
server.restart();
|
|
1383
1397
|
}
|
|
1384
1398
|
};
|
|
1385
|
-
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path5.join(root, cfg));
|
|
1386
|
-
const restartOnConfigAdd = (filename) => {
|
|
1387
|
-
if (possibleSvelteConfigs.includes(filename)) {
|
|
1388
|
-
triggerViteRestart(filename);
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
const restartOnConfigChange = (filename) => {
|
|
1392
|
-
if (filename === svelteConfigFile) {
|
|
1393
|
-
triggerViteRestart(filename);
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
1396
1399
|
const listenerCollection = {
|
|
1397
1400
|
add: [],
|
|
1398
1401
|
change: [emitChangeEventOnDependants],
|
|
1399
1402
|
unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
|
|
1400
1403
|
};
|
|
1401
|
-
if (svelteConfigFile) {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1404
|
+
if (svelteConfigFile !== false) {
|
|
1405
|
+
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path5.join(root, cfg));
|
|
1406
|
+
const restartOnConfigAdd = (filename) => {
|
|
1407
|
+
if (possibleSvelteConfigs.includes(filename)) {
|
|
1408
|
+
triggerViteRestart(filename);
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
const restartOnConfigChange = (filename) => {
|
|
1412
|
+
if (filename === svelteConfigFile) {
|
|
1413
|
+
triggerViteRestart(filename);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
if (svelteConfigFile) {
|
|
1417
|
+
listenerCollection.change.push(restartOnConfigChange);
|
|
1418
|
+
listenerCollection.unlink.push(restartOnConfigChange);
|
|
1419
|
+
} else {
|
|
1420
|
+
listenerCollection.add.push(restartOnConfigAdd);
|
|
1421
|
+
}
|
|
1406
1422
|
}
|
|
1407
1423
|
Object.entries(listenerCollection).forEach(([evt, listeners]) => {
|
|
1408
1424
|
if (listeners.length > 0) {
|
|
@@ -1489,6 +1505,95 @@ function generateSvelteMetadata(options) {
|
|
|
1489
1505
|
return metadata;
|
|
1490
1506
|
}
|
|
1491
1507
|
|
|
1508
|
+
// src/ui/inspector/plugin.ts
|
|
1509
|
+
import { createRequire as createRequire5 } from "module";
|
|
1510
|
+
var defaultInspectorOptions = {
|
|
1511
|
+
toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
|
|
1512
|
+
holdMode: false,
|
|
1513
|
+
showToggleButton: "active",
|
|
1514
|
+
toggleButtonPos: "top-right",
|
|
1515
|
+
customStyles: true
|
|
1516
|
+
};
|
|
1517
|
+
function svelteInspector() {
|
|
1518
|
+
let root;
|
|
1519
|
+
let rootRequire;
|
|
1520
|
+
let inspectorOptions;
|
|
1521
|
+
let append_to;
|
|
1522
|
+
return {
|
|
1523
|
+
name: "vite-plugin-svelte:inspector",
|
|
1524
|
+
apply: "serve",
|
|
1525
|
+
enforce: "pre",
|
|
1526
|
+
configResolved(config) {
|
|
1527
|
+
var _a, _b, _c;
|
|
1528
|
+
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1529
|
+
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) {
|
|
1530
|
+
inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
|
|
1531
|
+
}
|
|
1532
|
+
if (!vps || !inspectorOptions) {
|
|
1533
|
+
this.resolveId = this.load = this.transformIndexHtml = this.transform = () => {
|
|
1534
|
+
};
|
|
1535
|
+
} else {
|
|
1536
|
+
root = config.root || process.cwd();
|
|
1537
|
+
rootRequire = createRequire5(root);
|
|
1538
|
+
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1539
|
+
const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
|
|
1540
|
+
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
1541
|
+
}
|
|
1542
|
+
append_to = inspectorOptions.appendTo;
|
|
1543
|
+
}
|
|
1544
|
+
},
|
|
1545
|
+
async resolveId(importee, importer, options) {
|
|
1546
|
+
if (options == null ? void 0 : options.ssr) {
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
if (importee === "virtual:svelte-inspector-options") {
|
|
1550
|
+
return importee;
|
|
1551
|
+
}
|
|
1552
|
+
if (importee.startsWith("virtual:svelte-inspector:")) {
|
|
1553
|
+
const file = importee.replace("virtual:svelte-inspector:", "@sveltejs/vite-plugin-svelte/src/ui/inspector/");
|
|
1554
|
+
const path8 = rootRequire.resolve(file);
|
|
1555
|
+
if (path8) {
|
|
1556
|
+
return path8;
|
|
1557
|
+
} else {
|
|
1558
|
+
log.error.once(`failed to resolve ${file} for ${importee} from ${root}`);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
load(id) {
|
|
1563
|
+
if (id === "virtual:svelte-inspector-options") {
|
|
1564
|
+
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1565
|
+
}
|
|
1566
|
+
},
|
|
1567
|
+
transform(code, id, options) {
|
|
1568
|
+
if ((options == null ? void 0 : options.ssr) || !append_to) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
if (id.endsWith(append_to)) {
|
|
1572
|
+
return { code: `${code}
|
|
1573
|
+
import 'virtual:svelte-inspector:load-inspector.ts'` };
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1576
|
+
transformIndexHtml(html) {
|
|
1577
|
+
if (append_to) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
return {
|
|
1581
|
+
html,
|
|
1582
|
+
tags: [
|
|
1583
|
+
{
|
|
1584
|
+
tag: "script",
|
|
1585
|
+
injectTo: "body",
|
|
1586
|
+
attrs: {
|
|
1587
|
+
type: "module",
|
|
1588
|
+
src: "/@id/virtual:svelte-inspector:load-inspector.ts"
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
]
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1492
1597
|
// src/index.ts
|
|
1493
1598
|
function svelte(inlineOptions) {
|
|
1494
1599
|
if (process.env.DEBUG != null) {
|
|
@@ -1501,124 +1606,138 @@ function svelte(inlineOptions) {
|
|
|
1501
1606
|
let viteConfig;
|
|
1502
1607
|
let compileSvelte2;
|
|
1503
1608
|
let resolvedSvelteSSR;
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1609
|
+
const api = {};
|
|
1610
|
+
const plugins = [
|
|
1611
|
+
{
|
|
1612
|
+
name: "vite-plugin-svelte",
|
|
1613
|
+
enforce: "pre",
|
|
1614
|
+
api,
|
|
1615
|
+
async config(config, configEnv) {
|
|
1616
|
+
if (process.env.DEBUG) {
|
|
1617
|
+
log.setLevel("debug");
|
|
1618
|
+
} else if (config.logLevel) {
|
|
1619
|
+
log.setLevel(config.logLevel);
|
|
1620
|
+
}
|
|
1621
|
+
options = await preResolveOptions(inlineOptions, config, configEnv);
|
|
1622
|
+
const extraViteConfig = buildExtraViteConfig(options, config);
|
|
1623
|
+
log.debug("additional vite config", extraViteConfig);
|
|
1624
|
+
return extraViteConfig;
|
|
1625
|
+
},
|
|
1626
|
+
async configResolved(config) {
|
|
1627
|
+
options = resolveOptions(options, config);
|
|
1628
|
+
patchResolvedViteConfig(config, options);
|
|
1629
|
+
requestParser = buildIdParser(options);
|
|
1630
|
+
compileSvelte2 = createCompileSvelte(options);
|
|
1631
|
+
viteConfig = config;
|
|
1632
|
+
api.options = options;
|
|
1633
|
+
log.debug("resolved options", options);
|
|
1634
|
+
},
|
|
1635
|
+
async buildStart() {
|
|
1636
|
+
var _a;
|
|
1637
|
+
if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
|
|
1638
|
+
return;
|
|
1639
|
+
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
1640
|
+
if (isSvelteMetadataChanged) {
|
|
1641
|
+
viteConfig.server.force = true;
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1644
|
+
configureServer(server) {
|
|
1645
|
+
options.server = server;
|
|
1646
|
+
setupWatchers(options, cache, requestParser);
|
|
1647
|
+
},
|
|
1648
|
+
load(id, opts) {
|
|
1649
|
+
const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
|
|
1650
|
+
const svelteRequest = requestParser(id, !!ssr);
|
|
1651
|
+
if (svelteRequest) {
|
|
1652
|
+
const { filename, query } = svelteRequest;
|
|
1653
|
+
if (query.svelte && query.type === "style") {
|
|
1654
|
+
const css = cache.getCSS(svelteRequest);
|
|
1655
|
+
if (css) {
|
|
1656
|
+
log.debug(`load returns css for ${filename}`);
|
|
1657
|
+
return css;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (viteConfig.assetsInclude(filename)) {
|
|
1661
|
+
log.debug(`load returns raw content for ${filename}`);
|
|
1662
|
+
return fs7.readFileSync(filename, "utf-8");
|
|
1548
1663
|
}
|
|
1549
1664
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1665
|
+
},
|
|
1666
|
+
async resolveId(importee, importer, opts) {
|
|
1667
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1668
|
+
const svelteRequest = requestParser(importee, ssr);
|
|
1669
|
+
if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
|
|
1670
|
+
if (svelteRequest.query.type === "style") {
|
|
1671
|
+
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
1672
|
+
return svelteRequest.cssId;
|
|
1673
|
+
}
|
|
1674
|
+
log.debug(`resolveId resolved ${importee}`);
|
|
1675
|
+
return importee;
|
|
1553
1676
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1677
|
+
if (ssr && importee === "svelte") {
|
|
1678
|
+
if (!resolvedSvelteSSR) {
|
|
1679
|
+
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
|
|
1680
|
+
log.debug("resolved svelte to svelte/ssr");
|
|
1681
|
+
return svelteSSR;
|
|
1682
|
+
}, (err) => {
|
|
1683
|
+
log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
|
|
1684
|
+
return null;
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
return resolvedSvelteSSR;
|
|
1563
1688
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
}, (err) => {
|
|
1573
|
-
log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
|
|
1574
|
-
return null;
|
|
1575
|
-
});
|
|
1689
|
+
try {
|
|
1690
|
+
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
1691
|
+
if (resolved) {
|
|
1692
|
+
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
|
|
1693
|
+
return resolved;
|
|
1694
|
+
}
|
|
1695
|
+
} catch (e) {
|
|
1696
|
+
log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
|
|
1576
1697
|
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
const
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
return
|
|
1698
|
+
},
|
|
1699
|
+
async transform(code, id, opts) {
|
|
1700
|
+
var _a;
|
|
1701
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1702
|
+
const svelteRequest = requestParser(id, ssr);
|
|
1703
|
+
if (!svelteRequest || svelteRequest.query.svelte) {
|
|
1704
|
+
return;
|
|
1584
1705
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
compileData.dependencies.forEach((d) => {
|
|
1606
|
-
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1706
|
+
let compileData;
|
|
1707
|
+
try {
|
|
1708
|
+
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1709
|
+
} catch (e) {
|
|
1710
|
+
throw toRollupError(e, options);
|
|
1711
|
+
}
|
|
1712
|
+
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1713
|
+
cache.update(compileData);
|
|
1714
|
+
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|
|
1715
|
+
compileData.dependencies.forEach((d) => {
|
|
1716
|
+
ensureWatchedFile(options.server.watcher, d, options.root);
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
1720
|
+
return __spreadProps(__spreadValues({}, compileData.compiled.js), {
|
|
1721
|
+
meta: {
|
|
1722
|
+
vite: {
|
|
1723
|
+
lang: compileData.lang
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1607
1726
|
});
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
if (svelteRequest) {
|
|
1618
|
-
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1727
|
+
},
|
|
1728
|
+
handleHotUpdate(ctx) {
|
|
1729
|
+
if (!options.hot || !options.emitCss) {
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
|
|
1733
|
+
if (svelteRequest) {
|
|
1734
|
+
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1735
|
+
}
|
|
1619
1736
|
}
|
|
1620
1737
|
}
|
|
1621
|
-
|
|
1738
|
+
];
|
|
1739
|
+
plugins.push(svelteInspector());
|
|
1740
|
+
return plugins.filter(Boolean);
|
|
1622
1741
|
}
|
|
1623
1742
|
export {
|
|
1624
1743
|
svelte
|