@sveltejs/vite-plugin-svelte 1.3.0 → 1.4.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 +497 -381
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -13
- package/dist/index.js +490 -375
- package/dist/index.js.map +1 -1
- package/dist/preprocess.cjs +127 -0
- package/dist/preprocess.cjs.map +1 -0
- package/dist/preprocess.d.ts +9 -0
- package/dist/preprocess.js +96 -0
- package/dist/preprocess.js.map +1 -0
- package/package.json +6 -16
- package/src/handle-hot-update.ts +24 -24
- package/src/index.ts +23 -24
- package/src/preprocess.ts +114 -0
- package/src/utils/compile.ts +71 -23
- package/src/utils/id.ts +55 -3
- package/src/utils/load-raw.ts +132 -0
- package/src/utils/options.ts +16 -9
- package/src/utils/preprocess.ts +9 -150
- package/src/utils/vite-plugin-svelte-stats.ts +50 -39
- package/src/utils/__tests__/sourcemap.spec.ts +0 -25
- package/src/utils/sourcemap.ts +0 -58
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var src_exports = {};
|
|
28
28
|
__export(src_exports, {
|
|
29
29
|
loadSvelteConfig: () => loadSvelteConfig,
|
|
30
|
-
svelte: () => svelte
|
|
30
|
+
svelte: () => svelte,
|
|
31
|
+
vitePreprocess: () => vitePreprocess
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(src_exports);
|
|
33
34
|
|
|
@@ -36,7 +37,7 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" +
|
|
|
36
37
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
37
38
|
|
|
38
39
|
// src/index.ts
|
|
39
|
-
var
|
|
40
|
+
var import_fs8 = __toESM(require("fs"), 1);
|
|
40
41
|
var import_vitefu4 = require("vitefu");
|
|
41
42
|
|
|
42
43
|
// src/utils/log.ts
|
|
@@ -213,7 +214,7 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
|
|
|
213
214
|
log.debug(`handleHotUpdate called before initial transform for ${svelteRequest.id}`);
|
|
214
215
|
return;
|
|
215
216
|
}
|
|
216
|
-
const { read, server } = ctx;
|
|
217
|
+
const { read, server, modules } = ctx;
|
|
217
218
|
const cachedJS = cache.getJS(svelteRequest);
|
|
218
219
|
const cachedCss = cache.getCSS(svelteRequest);
|
|
219
220
|
const content = await read();
|
|
@@ -225,34 +226,35 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
|
|
|
225
226
|
cache.setError(svelteRequest, e);
|
|
226
227
|
throw e;
|
|
227
228
|
}
|
|
228
|
-
const affectedModules =
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const jsUpdated = mainModule && jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename);
|
|
237
|
-
if (jsUpdated) {
|
|
238
|
-
log.debug(`handleHotUpdate js changed for ${svelteRequest.id}`);
|
|
239
|
-
affectedModules.add(mainModule);
|
|
229
|
+
const affectedModules = [...modules];
|
|
230
|
+
const cssIdx = modules.findIndex((m) => m.id === svelteRequest.cssId);
|
|
231
|
+
if (cssIdx > -1) {
|
|
232
|
+
const cssUpdated = cssChanged(cachedCss, compileData.compiled.css);
|
|
233
|
+
if (!cssUpdated) {
|
|
234
|
+
log.debug(`skipping unchanged css for ${svelteRequest.cssId}`);
|
|
235
|
+
affectedModules.splice(cssIdx, 1);
|
|
236
|
+
}
|
|
240
237
|
}
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
const jsIdx = modules.findIndex((m) => m.id === svelteRequest.id);
|
|
239
|
+
if (jsIdx > -1) {
|
|
240
|
+
const jsUpdated = jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename);
|
|
241
|
+
if (!jsUpdated) {
|
|
242
|
+
log.debug(`skipping unchanged js for ${svelteRequest.id}`);
|
|
243
|
+
affectedModules.splice(jsIdx, 1);
|
|
244
|
+
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
245
|
+
}
|
|
243
246
|
}
|
|
244
|
-
const
|
|
245
|
-
const ssrModulesToInvalidate = result.filter((m) => !!m.ssrTransformResult);
|
|
247
|
+
const ssrModulesToInvalidate = affectedModules.filter((m) => !!m.ssrTransformResult);
|
|
246
248
|
if (ssrModulesToInvalidate.length > 0) {
|
|
247
249
|
log.debug(`invalidating modules ${ssrModulesToInvalidate.map((m) => m.id).join(", ")}`);
|
|
248
250
|
ssrModulesToInvalidate.forEach((moduleNode) => server.moduleGraph.invalidateModule(moduleNode));
|
|
249
251
|
}
|
|
250
|
-
if (
|
|
252
|
+
if (affectedModules.length > 0) {
|
|
251
253
|
log.debug(
|
|
252
|
-
`handleHotUpdate for ${svelteRequest.id} result: ${
|
|
254
|
+
`handleHotUpdate for ${svelteRequest.id} result: ${affectedModules.map((m) => m.id).join(", ")}`
|
|
253
255
|
);
|
|
254
256
|
}
|
|
255
|
-
return
|
|
257
|
+
return affectedModules;
|
|
256
258
|
}
|
|
257
259
|
function cssChanged(prev, next) {
|
|
258
260
|
return !isCodeEqual(prev?.code, next?.code);
|
|
@@ -289,7 +291,7 @@ function normalizeJsCode(code) {
|
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
// src/utils/compile.ts
|
|
292
|
-
var
|
|
294
|
+
var import_compiler2 = require("svelte/compiler");
|
|
293
295
|
var import_svelte_hmr = require("svelte-hmr");
|
|
294
296
|
|
|
295
297
|
// src/utils/hash.ts
|
|
@@ -316,12 +318,210 @@ function toSafe(base64) {
|
|
|
316
318
|
return base64.replace(replaceRE, (x) => replacements[x]);
|
|
317
319
|
}
|
|
318
320
|
|
|
321
|
+
// src/utils/preprocess.ts
|
|
322
|
+
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
323
|
+
var import_compiler = require("svelte/compiler");
|
|
324
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
325
|
+
|
|
326
|
+
// src/preprocess.ts
|
|
327
|
+
var import_path = __toESM(require("path"), 1);
|
|
328
|
+
var vite = __toESM(require("vite"), 1);
|
|
329
|
+
var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss", "sss"];
|
|
330
|
+
var supportedScriptLangs = ["ts"];
|
|
331
|
+
function vitePreprocess(opts) {
|
|
332
|
+
const preprocessor = {};
|
|
333
|
+
if (opts?.script !== false) {
|
|
334
|
+
preprocessor.script = viteScript().script;
|
|
335
|
+
}
|
|
336
|
+
if (opts?.style !== false) {
|
|
337
|
+
const styleOpts = typeof opts?.style == "object" ? opts?.style : void 0;
|
|
338
|
+
preprocessor.style = viteStyle(styleOpts).style;
|
|
339
|
+
}
|
|
340
|
+
return preprocessor;
|
|
341
|
+
}
|
|
342
|
+
function viteScript() {
|
|
343
|
+
return {
|
|
344
|
+
async script({ attributes, content, filename = "" }) {
|
|
345
|
+
const lang = attributes.lang;
|
|
346
|
+
if (!supportedScriptLangs.includes(lang))
|
|
347
|
+
return;
|
|
348
|
+
const transformResult = await vite.transformWithEsbuild(content, filename, {
|
|
349
|
+
loader: lang,
|
|
350
|
+
target: "esnext",
|
|
351
|
+
tsconfigRaw: {
|
|
352
|
+
compilerOptions: {
|
|
353
|
+
importsNotUsedAsValues: "preserve",
|
|
354
|
+
preserveValueImports: true
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return {
|
|
359
|
+
code: transformResult.code,
|
|
360
|
+
map: transformResult.map
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function viteStyle(config = {}) {
|
|
366
|
+
let transform;
|
|
367
|
+
const style = async ({ attributes, content, filename = "" }) => {
|
|
368
|
+
const lang = attributes.lang;
|
|
369
|
+
if (!supportedStyleLangs.includes(lang))
|
|
370
|
+
return;
|
|
371
|
+
if (!transform) {
|
|
372
|
+
let resolvedConfig;
|
|
373
|
+
if (style.__resolvedConfig) {
|
|
374
|
+
resolvedConfig = style.__resolvedConfig;
|
|
375
|
+
} else if (isResolvedConfig(config)) {
|
|
376
|
+
resolvedConfig = config;
|
|
377
|
+
} else {
|
|
378
|
+
resolvedConfig = await vite.resolveConfig(
|
|
379
|
+
config,
|
|
380
|
+
process.env.NODE_ENV === "production" ? "build" : "serve"
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
transform = getCssTransformFn(resolvedConfig);
|
|
384
|
+
}
|
|
385
|
+
const moduleId = `${filename}.${lang}`;
|
|
386
|
+
const result = await transform(content, moduleId);
|
|
387
|
+
if (result.map?.sources?.[0] === moduleId) {
|
|
388
|
+
result.map.sources[0] = import_path.default.basename(filename);
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
code: result.code,
|
|
392
|
+
map: result.map ?? void 0
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
style.__resolvedConfig = null;
|
|
396
|
+
return { style };
|
|
397
|
+
}
|
|
398
|
+
function getCssTransformFn(config) {
|
|
399
|
+
if (vite.preprocessCSS) {
|
|
400
|
+
return async (code, filename) => {
|
|
401
|
+
return vite.preprocessCSS(code, filename, config);
|
|
402
|
+
};
|
|
403
|
+
} else {
|
|
404
|
+
const pluginName = "vite:css";
|
|
405
|
+
const plugin = config.plugins.find((p) => p.name === pluginName);
|
|
406
|
+
if (!plugin) {
|
|
407
|
+
throw new Error(`failed to find plugin ${pluginName}`);
|
|
408
|
+
}
|
|
409
|
+
if (!plugin.transform) {
|
|
410
|
+
throw new Error(`plugin ${pluginName} has no transform`);
|
|
411
|
+
}
|
|
412
|
+
return plugin.transform.bind(null);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function isResolvedConfig(config) {
|
|
416
|
+
return !!config.inlineConfig;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/utils/preprocess.ts
|
|
420
|
+
function createVitePreprocessorGroup(config) {
|
|
421
|
+
return {
|
|
422
|
+
markup({ content, filename }) {
|
|
423
|
+
return (0, import_compiler.preprocess)(content, vitePreprocess({ style: config }), { filename });
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
428
|
+
return {
|
|
429
|
+
style({ content, filename }) {
|
|
430
|
+
const s = new import_magic_string.default(content);
|
|
431
|
+
s.append(" *{}");
|
|
432
|
+
return {
|
|
433
|
+
code: s.toString(),
|
|
434
|
+
map: s.generateDecodedMap({
|
|
435
|
+
source: filename ? import_path2.default.basename(filename) : void 0,
|
|
436
|
+
hires: true
|
|
437
|
+
})
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function buildExtraPreprocessors(options, config) {
|
|
443
|
+
const prependPreprocessors = [];
|
|
444
|
+
const appendPreprocessors = [];
|
|
445
|
+
if (options.experimental?.useVitePreprocess) {
|
|
446
|
+
log.warn(
|
|
447
|
+
"`experimental.useVitePreprocess` is deprecated. Use the `vitePreprocess()` preprocessor instead. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md for more information."
|
|
448
|
+
);
|
|
449
|
+
prependPreprocessors.push(createVitePreprocessorGroup(config));
|
|
450
|
+
}
|
|
451
|
+
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
|
|
452
|
+
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
453
|
+
log.warn(
|
|
454
|
+
`The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated.map((p) => p.name).join(", ")}`
|
|
455
|
+
);
|
|
456
|
+
pluginsWithPreprocessorsDeprecated.forEach((p) => {
|
|
457
|
+
if (!p.api) {
|
|
458
|
+
p.api = {};
|
|
459
|
+
}
|
|
460
|
+
if (p.api.sveltePreprocess === void 0) {
|
|
461
|
+
p.api.sveltePreprocess = p.sveltePreprocess;
|
|
462
|
+
} else {
|
|
463
|
+
log.error(
|
|
464
|
+
`ignoring plugin.sveltePreprocess of ${p.name} because it already defined plugin.api.sveltePreprocess.`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
|
|
470
|
+
const ignored = [], included = [];
|
|
471
|
+
for (const p of pluginsWithPreprocessors) {
|
|
472
|
+
if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && options.ignorePluginPreprocessors?.includes(p.name)) {
|
|
473
|
+
ignored.push(p);
|
|
474
|
+
} else {
|
|
475
|
+
included.push(p);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (ignored.length > 0) {
|
|
479
|
+
log.debug(
|
|
480
|
+
`Ignoring svelte preprocessors defined by these vite plugins: ${ignored.map((p) => p.name).join(", ")}`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (included.length > 0) {
|
|
484
|
+
log.debug(
|
|
485
|
+
`Adding svelte preprocessors defined by these vite plugins: ${included.map((p) => p.name).join(", ")}`
|
|
486
|
+
);
|
|
487
|
+
appendPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess));
|
|
488
|
+
}
|
|
489
|
+
return { prependPreprocessors, appendPreprocessors };
|
|
490
|
+
}
|
|
491
|
+
function addExtraPreprocessors(options, config) {
|
|
492
|
+
const { prependPreprocessors, appendPreprocessors } = buildExtraPreprocessors(options, config);
|
|
493
|
+
if (prependPreprocessors.length > 0 || appendPreprocessors.length > 0) {
|
|
494
|
+
if (!options.preprocess) {
|
|
495
|
+
options.preprocess = [...prependPreprocessors, ...appendPreprocessors];
|
|
496
|
+
} else if (Array.isArray(options.preprocess)) {
|
|
497
|
+
options.preprocess.unshift(...prependPreprocessors);
|
|
498
|
+
options.preprocess.push(...appendPreprocessors);
|
|
499
|
+
} else {
|
|
500
|
+
options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
319
505
|
// src/utils/compile.ts
|
|
506
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
320
507
|
var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
508
|
+
function mapSourcesToRelative(map, filename) {
|
|
509
|
+
if (map?.sources) {
|
|
510
|
+
map.sources = map.sources.map((s) => {
|
|
511
|
+
if (import_path3.default.isAbsolute(s)) {
|
|
512
|
+
const relative = import_path3.default.relative(filename, s);
|
|
513
|
+
return relative === "" ? import_path3.default.basename(filename) : relative;
|
|
514
|
+
} else {
|
|
515
|
+
return s;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
321
520
|
var _createCompileSvelte = (makeHot) => {
|
|
322
521
|
let stats;
|
|
522
|
+
const devStylePreprocessor = createInjectScopeEverythingRulePreprocessorGroup();
|
|
323
523
|
return async function compileSvelte2(svelteRequest, code, options) {
|
|
324
|
-
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
|
|
524
|
+
const { filename, normalizedFilename, cssId, ssr, raw } = svelteRequest;
|
|
325
525
|
const { emitCss = true } = options;
|
|
326
526
|
const dependencies = [];
|
|
327
527
|
if (options.stats) {
|
|
@@ -343,7 +543,7 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
343
543
|
}
|
|
344
544
|
const compileOptions = {
|
|
345
545
|
...options.compilerOptions,
|
|
346
|
-
filename,
|
|
546
|
+
filename: normalizedFilename,
|
|
347
547
|
generate: ssr ? "ssr" : "dom",
|
|
348
548
|
format: "esm"
|
|
349
549
|
};
|
|
@@ -360,9 +560,17 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
360
560
|
}
|
|
361
561
|
}
|
|
362
562
|
let preprocessed;
|
|
363
|
-
|
|
563
|
+
let preprocessors = options.preprocess;
|
|
564
|
+
if (!options.isBuild && options.emitCss && options.hot) {
|
|
565
|
+
if (!Array.isArray(preprocessors)) {
|
|
566
|
+
preprocessors = preprocessors ? [preprocessors, devStylePreprocessor] : [devStylePreprocessor];
|
|
567
|
+
} else {
|
|
568
|
+
preprocessors = preprocessors.concat(devStylePreprocessor);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (preprocessors) {
|
|
364
572
|
try {
|
|
365
|
-
preprocessed = await (0,
|
|
573
|
+
preprocessed = await (0, import_compiler2.preprocess)(code, preprocessors, { filename });
|
|
366
574
|
} catch (e) {
|
|
367
575
|
e.message = `Error while preprocessing ${filename}${e.message ? ` - ${e.message}` : ""}`;
|
|
368
576
|
throw e;
|
|
@@ -372,6 +580,12 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
372
580
|
if (preprocessed.map)
|
|
373
581
|
compileOptions.sourcemap = preprocessed.map;
|
|
374
582
|
}
|
|
583
|
+
if (typeof preprocessed?.map === "object") {
|
|
584
|
+
mapSourcesToRelative(preprocessed?.map, filename);
|
|
585
|
+
}
|
|
586
|
+
if (raw && svelteRequest.query.type === "preprocessed") {
|
|
587
|
+
return { preprocessed: preprocessed ?? { code } };
|
|
588
|
+
}
|
|
375
589
|
const finalCode = preprocessed ? preprocessed.code : code;
|
|
376
590
|
const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
|
|
377
591
|
filename,
|
|
@@ -388,25 +602,29 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
388
602
|
...dynamicCompileOptions
|
|
389
603
|
} : compileOptions;
|
|
390
604
|
const endStat = stats?.start(filename);
|
|
391
|
-
const compiled = (0,
|
|
605
|
+
const compiled = (0, import_compiler2.compile)(finalCode, finalCompileOptions);
|
|
392
606
|
if (endStat) {
|
|
393
607
|
endStat();
|
|
394
608
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
609
|
+
mapSourcesToRelative(compiled.js?.map, filename);
|
|
610
|
+
mapSourcesToRelative(compiled.css?.map, filename);
|
|
611
|
+
if (!raw) {
|
|
612
|
+
const hasCss = compiled.css?.code?.trim().length > 0;
|
|
613
|
+
if (emitCss && hasCss) {
|
|
614
|
+
compiled.js.code += `
|
|
398
615
|
import ${JSON.stringify(cssId)};
|
|
399
616
|
`;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
617
|
+
}
|
|
618
|
+
if (!ssr && makeHot) {
|
|
619
|
+
compiled.js.code = makeHot({
|
|
620
|
+
id: filename,
|
|
621
|
+
compiledCode: compiled.js.code,
|
|
622
|
+
hotOptions: { ...options.hot, injectCss: options.hot?.injectCss === true && hasCss },
|
|
623
|
+
compiled,
|
|
624
|
+
originalCode: code,
|
|
625
|
+
compileOptions: finalCompileOptions
|
|
626
|
+
});
|
|
627
|
+
}
|
|
410
628
|
}
|
|
411
629
|
compiled.js.dependencies = dependencies;
|
|
412
630
|
return {
|
|
@@ -415,7 +633,8 @@ import ${JSON.stringify(cssId)};
|
|
|
415
633
|
lang: code.match(scriptLangRE)?.[1] || "js",
|
|
416
634
|
compiled,
|
|
417
635
|
ssr,
|
|
418
|
-
dependencies
|
|
636
|
+
dependencies,
|
|
637
|
+
preprocessed: preprocessed ?? { code }
|
|
419
638
|
};
|
|
420
639
|
};
|
|
421
640
|
};
|
|
@@ -425,7 +644,7 @@ function buildMakeHot(options) {
|
|
|
425
644
|
const hotApi = options?.hot?.hotApi;
|
|
426
645
|
const adapter = options?.hot?.adapter;
|
|
427
646
|
return (0, import_svelte_hmr.createMakeHot)({
|
|
428
|
-
walk:
|
|
647
|
+
walk: import_compiler2.walk,
|
|
429
648
|
hotApi,
|
|
430
649
|
adapter,
|
|
431
650
|
hotOptions: { noOverlay: true, ...options.hot }
|
|
@@ -443,6 +662,16 @@ var import_vite2 = require("vite");
|
|
|
443
662
|
var fs = __toESM(require("fs"), 1);
|
|
444
663
|
var VITE_FS_PREFIX = "/@fs/";
|
|
445
664
|
var IS_WINDOWS = process.platform === "win32";
|
|
665
|
+
var SUPPORTED_COMPILER_OPTIONS = [
|
|
666
|
+
"generate",
|
|
667
|
+
"dev",
|
|
668
|
+
"css",
|
|
669
|
+
"hydratable",
|
|
670
|
+
"customElement",
|
|
671
|
+
"immutable",
|
|
672
|
+
"enableSourcemap"
|
|
673
|
+
];
|
|
674
|
+
var TYPES_WITH_COMPILER_OPTIONS = ["style", "script", "all"];
|
|
446
675
|
function splitId(id) {
|
|
447
676
|
const parts = id.split(`?`, 2);
|
|
448
677
|
const filename = parts[0];
|
|
@@ -451,9 +680,11 @@ function splitId(id) {
|
|
|
451
680
|
}
|
|
452
681
|
function parseToSvelteRequest(id, filename, rawQuery, root, timestamp, ssr) {
|
|
453
682
|
const query = parseRequestQuery(rawQuery);
|
|
454
|
-
|
|
683
|
+
const rawOrDirect = !!(query.raw || query.direct);
|
|
684
|
+
if (query.url || !query.svelte && rawOrDirect) {
|
|
455
685
|
return;
|
|
456
686
|
}
|
|
687
|
+
const raw = rawOrDirect;
|
|
457
688
|
const normalizedFilename = normalize(filename, root);
|
|
458
689
|
const cssId = createVirtualImportId(filename, root, "style");
|
|
459
690
|
return {
|
|
@@ -463,7 +694,8 @@ function parseToSvelteRequest(id, filename, rawQuery, root, timestamp, ssr) {
|
|
|
463
694
|
cssId,
|
|
464
695
|
query,
|
|
465
696
|
timestamp,
|
|
466
|
-
ssr
|
|
697
|
+
ssr,
|
|
698
|
+
raw
|
|
467
699
|
};
|
|
468
700
|
}
|
|
469
701
|
function createVirtualImportId(filename, root, type) {
|
|
@@ -485,6 +717,33 @@ function parseRequestQuery(rawQuery) {
|
|
|
485
717
|
query[key] = true;
|
|
486
718
|
}
|
|
487
719
|
}
|
|
720
|
+
const compilerOptions = query.compilerOptions;
|
|
721
|
+
if (compilerOptions) {
|
|
722
|
+
if (!((query.raw || query.direct) && TYPES_WITH_COMPILER_OPTIONS.includes(query.type))) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
`Invalid compilerOptions in query ${rawQuery}. CompilerOptions are only supported for raw or direct queries with type in "${TYPES_WITH_COMPILER_OPTIONS.join(
|
|
725
|
+
", "
|
|
726
|
+
)}" e.g. '?svelte&raw&type=script&compilerOptions={"generate":"ssr","dev":false}`
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
const parsed = JSON.parse(compilerOptions);
|
|
731
|
+
const invalid = Object.keys(parsed).filter(
|
|
732
|
+
(key) => !SUPPORTED_COMPILER_OPTIONS.includes(key)
|
|
733
|
+
);
|
|
734
|
+
if (invalid.length) {
|
|
735
|
+
throw new Error(
|
|
736
|
+
`Invalid compilerOptions in query ${rawQuery}: ${invalid.join(
|
|
737
|
+
", "
|
|
738
|
+
)}. Supported: ${SUPPORTED_COMPILER_OPTIONS.join(", ")}`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
query.compilerOptions = parsed;
|
|
742
|
+
} catch (e) {
|
|
743
|
+
log.error("failed to parse request query compilerOptions", e);
|
|
744
|
+
throw e;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
488
747
|
return query;
|
|
489
748
|
}
|
|
490
749
|
function normalize(filename, normalizedRoot) {
|
|
@@ -516,11 +775,11 @@ function buildIdParser(options) {
|
|
|
516
775
|
}
|
|
517
776
|
|
|
518
777
|
// src/utils/options.ts
|
|
519
|
-
var
|
|
778
|
+
var import_vite4 = require("vite");
|
|
520
779
|
|
|
521
780
|
// src/utils/load-svelte-config.ts
|
|
522
781
|
var import_module = require("module");
|
|
523
|
-
var
|
|
782
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
524
783
|
var import_fs = __toESM(require("fs"), 1);
|
|
525
784
|
var import_url = require("url");
|
|
526
785
|
var esmRequire;
|
|
@@ -586,13 +845,13 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
586
845
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
|
587
846
|
const root = viteConfig?.root || process.cwd();
|
|
588
847
|
if (inlineOptions?.configFile) {
|
|
589
|
-
const abolutePath =
|
|
848
|
+
const abolutePath = import_path4.default.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : import_path4.default.resolve(root, inlineOptions.configFile);
|
|
590
849
|
if (!import_fs.default.existsSync(abolutePath)) {
|
|
591
850
|
throw new Error(`failed to find svelte config file ${abolutePath}.`);
|
|
592
851
|
}
|
|
593
852
|
return abolutePath;
|
|
594
853
|
} else {
|
|
595
|
-
const existingKnownConfigFiles = knownSvelteConfigNames.map((candidate) =>
|
|
854
|
+
const existingKnownConfigFiles = knownSvelteConfigNames.map((candidate) => import_path4.default.resolve(root, candidate)).filter((file) => import_fs.default.existsSync(file));
|
|
596
855
|
if (existingKnownConfigFiles.length === 0) {
|
|
597
856
|
log.debug(`no svelte config found at ${root}`);
|
|
598
857
|
return;
|
|
@@ -627,11 +886,11 @@ var SVELTE_HMR_IMPORTS = [
|
|
|
627
886
|
var SVELTE_EXPORT_CONDITIONS = ["svelte"];
|
|
628
887
|
|
|
629
888
|
// src/utils/options.ts
|
|
630
|
-
var
|
|
889
|
+
var import_path7 = __toESM(require("path"), 1);
|
|
631
890
|
|
|
632
891
|
// src/utils/esbuild.ts
|
|
633
892
|
var import_fs2 = require("fs");
|
|
634
|
-
var
|
|
893
|
+
var import_compiler4 = require("svelte/compiler");
|
|
635
894
|
|
|
636
895
|
// src/utils/error.ts
|
|
637
896
|
function toRollupError(error, options) {
|
|
@@ -687,8 +946,8 @@ function formatFrameForVite(frame) {
|
|
|
687
946
|
}
|
|
688
947
|
|
|
689
948
|
// src/utils/svelte-version.ts
|
|
690
|
-
var
|
|
691
|
-
var svelteVersion = parseVersion(
|
|
949
|
+
var import_compiler3 = require("svelte/compiler");
|
|
950
|
+
var svelteVersion = parseVersion(import_compiler3.VERSION);
|
|
692
951
|
function parseVersion(version) {
|
|
693
952
|
const segments = version.split(".", 3).map((s) => parseInt(s, 10));
|
|
694
953
|
while (segments.length < 3) {
|
|
@@ -763,7 +1022,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
763
1022
|
let preprocessed;
|
|
764
1023
|
if (options.preprocess) {
|
|
765
1024
|
try {
|
|
766
|
-
preprocessed = await (0,
|
|
1025
|
+
preprocessed = await (0, import_compiler4.preprocess)(code, options.preprocess, { filename });
|
|
767
1026
|
} catch (e) {
|
|
768
1027
|
e.message = `Error while preprocessing ${filename}${e.message ? ` - ${e.message}` : ""}`;
|
|
769
1028
|
throw e;
|
|
@@ -785,275 +1044,19 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
785
1044
|
...dynamicCompileOptions
|
|
786
1045
|
} : compileOptions;
|
|
787
1046
|
const endStat = statsCollection?.start(filename);
|
|
788
|
-
const compiled = (0,
|
|
1047
|
+
const compiled = (0, import_compiler4.compile)(finalCode, finalCompileOptions);
|
|
789
1048
|
if (endStat) {
|
|
790
1049
|
endStat();
|
|
791
1050
|
}
|
|
792
1051
|
return compiled.js.code + "//# sourceMappingURL=" + compiled.js.map.toUrl();
|
|
793
1052
|
}
|
|
794
1053
|
|
|
795
|
-
// src/utils/preprocess.ts
|
|
796
|
-
var vite = __toESM(require("vite"), 1);
|
|
797
|
-
var import_magic_string2 = __toESM(require("magic-string"), 1);
|
|
798
|
-
var import_compiler4 = require("svelte/compiler");
|
|
799
|
-
|
|
800
|
-
// src/utils/sourcemap.ts
|
|
801
|
-
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
802
|
-
async function buildMagicString(from, to, options) {
|
|
803
|
-
let diff_match_patch, DIFF_DELETE, DIFF_INSERT;
|
|
804
|
-
try {
|
|
805
|
-
const dmpPkg = await import("diff-match-patch");
|
|
806
|
-
diff_match_patch = dmpPkg.diff_match_patch;
|
|
807
|
-
DIFF_INSERT = dmpPkg.DIFF_INSERT;
|
|
808
|
-
DIFF_DELETE = dmpPkg.DIFF_DELETE;
|
|
809
|
-
} catch (e) {
|
|
810
|
-
log.error.once(
|
|
811
|
-
'Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.'
|
|
812
|
-
);
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
815
|
-
const dmp = new diff_match_patch();
|
|
816
|
-
const diffs = dmp.diff_main(from, to);
|
|
817
|
-
dmp.diff_cleanupSemantic(diffs);
|
|
818
|
-
const m = new import_magic_string.default(from, options);
|
|
819
|
-
let pos = 0;
|
|
820
|
-
for (let i = 0; i < diffs.length; i++) {
|
|
821
|
-
const diff = diffs[i];
|
|
822
|
-
const nextDiff = diffs[i + 1];
|
|
823
|
-
if (diff[0] === DIFF_DELETE) {
|
|
824
|
-
if (nextDiff?.[0] === DIFF_INSERT) {
|
|
825
|
-
m.overwrite(pos, pos + diff[1].length, nextDiff[1]);
|
|
826
|
-
i++;
|
|
827
|
-
} else {
|
|
828
|
-
m.remove(pos, pos + diff[1].length);
|
|
829
|
-
}
|
|
830
|
-
pos += diff[1].length;
|
|
831
|
-
} else if (diff[0] === DIFF_INSERT) {
|
|
832
|
-
if (nextDiff) {
|
|
833
|
-
m.appendRight(pos, diff[1]);
|
|
834
|
-
} else {
|
|
835
|
-
m.append(diff[1]);
|
|
836
|
-
}
|
|
837
|
-
} else {
|
|
838
|
-
pos += diff[1].length;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
return m;
|
|
842
|
-
}
|
|
843
|
-
async function buildSourceMap(from, to, filename) {
|
|
844
|
-
const m = await buildMagicString(from, to, { filename });
|
|
845
|
-
return m ? m.generateDecodedMap({ source: filename, hires: true, includeContent: false }) : null;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// src/utils/preprocess.ts
|
|
849
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
850
|
-
var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss"];
|
|
851
|
-
var supportedScriptLangs = ["ts"];
|
|
852
|
-
function createViteScriptPreprocessor() {
|
|
853
|
-
return async ({ attributes, content, filename = "" }) => {
|
|
854
|
-
const lang = attributes.lang;
|
|
855
|
-
if (!supportedScriptLangs.includes(lang))
|
|
856
|
-
return;
|
|
857
|
-
const transformResult = await vite.transformWithEsbuild(content, filename, {
|
|
858
|
-
loader: lang,
|
|
859
|
-
target: "esnext",
|
|
860
|
-
tsconfigRaw: {
|
|
861
|
-
compilerOptions: {
|
|
862
|
-
importsNotUsedAsValues: "preserve",
|
|
863
|
-
preserveValueImports: true
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
return {
|
|
868
|
-
code: transformResult.code,
|
|
869
|
-
map: transformResult.map
|
|
870
|
-
};
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
function createViteStylePreprocessor(config) {
|
|
874
|
-
const transform = getCssTransformFn(config);
|
|
875
|
-
return async ({ attributes, content, filename = "" }) => {
|
|
876
|
-
const lang = attributes.lang;
|
|
877
|
-
if (!supportedStyleLangs.includes(lang))
|
|
878
|
-
return;
|
|
879
|
-
const moduleId = `${filename}.${lang}`;
|
|
880
|
-
const result = await transform(content, moduleId);
|
|
881
|
-
if (result.map?.sources?.[0] === moduleId) {
|
|
882
|
-
result.map.sources[0] = import_path2.default.basename(filename);
|
|
883
|
-
}
|
|
884
|
-
return {
|
|
885
|
-
code: result.code,
|
|
886
|
-
map: result.map ?? void 0
|
|
887
|
-
};
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
function getCssTransformFn(config) {
|
|
891
|
-
if (vite.preprocessCSS) {
|
|
892
|
-
return async (code, filename) => {
|
|
893
|
-
return vite.preprocessCSS(code, filename, config);
|
|
894
|
-
};
|
|
895
|
-
} else {
|
|
896
|
-
const pluginName = "vite:css";
|
|
897
|
-
const plugin = config.plugins.find((p) => p.name === pluginName);
|
|
898
|
-
if (!plugin) {
|
|
899
|
-
throw new Error(`failed to find plugin ${pluginName}`);
|
|
900
|
-
}
|
|
901
|
-
if (!plugin.transform) {
|
|
902
|
-
throw new Error(`plugin ${pluginName} has no transform`);
|
|
903
|
-
}
|
|
904
|
-
return plugin.transform.bind(null);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
function createVitePreprocessorGroup(config) {
|
|
908
|
-
return {
|
|
909
|
-
markup({ content, filename }) {
|
|
910
|
-
return (0, import_compiler4.preprocess)(
|
|
911
|
-
content,
|
|
912
|
-
{
|
|
913
|
-
script: createViteScriptPreprocessor(),
|
|
914
|
-
style: createViteStylePreprocessor(config)
|
|
915
|
-
},
|
|
916
|
-
{ filename }
|
|
917
|
-
);
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
function createInjectScopeEverythingRulePreprocessorGroup() {
|
|
922
|
-
return {
|
|
923
|
-
style({ content, filename }) {
|
|
924
|
-
const s = new import_magic_string2.default(content);
|
|
925
|
-
s.append(" *{}");
|
|
926
|
-
return {
|
|
927
|
-
code: s.toString(),
|
|
928
|
-
map: s.generateDecodedMap({
|
|
929
|
-
source: filename ? import_path2.default.basename(filename) : void 0,
|
|
930
|
-
hires: true
|
|
931
|
-
})
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
function buildExtraPreprocessors(options, config) {
|
|
937
|
-
const prependPreprocessors = [];
|
|
938
|
-
const appendPreprocessors = [];
|
|
939
|
-
if (options.experimental?.useVitePreprocess) {
|
|
940
|
-
log.debug("adding vite preprocessor");
|
|
941
|
-
prependPreprocessors.push(createVitePreprocessorGroup(config));
|
|
942
|
-
}
|
|
943
|
-
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
|
|
944
|
-
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
945
|
-
log.warn(
|
|
946
|
-
`The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated.map((p) => p.name).join(", ")}`
|
|
947
|
-
);
|
|
948
|
-
pluginsWithPreprocessorsDeprecated.forEach((p) => {
|
|
949
|
-
if (!p.api) {
|
|
950
|
-
p.api = {};
|
|
951
|
-
}
|
|
952
|
-
if (p.api.sveltePreprocess === void 0) {
|
|
953
|
-
p.api.sveltePreprocess = p.sveltePreprocess;
|
|
954
|
-
} else {
|
|
955
|
-
log.error(
|
|
956
|
-
`ignoring plugin.sveltePreprocess of ${p.name} because it already defined plugin.api.sveltePreprocess.`
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
|
|
962
|
-
const ignored = [], included = [];
|
|
963
|
-
for (const p of pluginsWithPreprocessors) {
|
|
964
|
-
if (options.ignorePluginPreprocessors === true || Array.isArray(options.ignorePluginPreprocessors) && options.ignorePluginPreprocessors?.includes(p.name)) {
|
|
965
|
-
ignored.push(p);
|
|
966
|
-
} else {
|
|
967
|
-
included.push(p);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (ignored.length > 0) {
|
|
971
|
-
log.debug(
|
|
972
|
-
`Ignoring svelte preprocessors defined by these vite plugins: ${ignored.map((p) => p.name).join(", ")}`
|
|
973
|
-
);
|
|
974
|
-
}
|
|
975
|
-
if (included.length > 0) {
|
|
976
|
-
log.debug(
|
|
977
|
-
`Adding svelte preprocessors defined by these vite plugins: ${included.map((p) => p.name).join(", ")}`
|
|
978
|
-
);
|
|
979
|
-
appendPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess));
|
|
980
|
-
}
|
|
981
|
-
if (options.hot && options.emitCss) {
|
|
982
|
-
appendPreprocessors.push(createInjectScopeEverythingRulePreprocessorGroup());
|
|
983
|
-
}
|
|
984
|
-
return { prependPreprocessors, appendPreprocessors };
|
|
985
|
-
}
|
|
986
|
-
function addExtraPreprocessors(options, config) {
|
|
987
|
-
const { prependPreprocessors, appendPreprocessors } = buildExtraPreprocessors(options, config);
|
|
988
|
-
if (prependPreprocessors.length > 0 || appendPreprocessors.length > 0) {
|
|
989
|
-
if (!options.preprocess) {
|
|
990
|
-
options.preprocess = [...prependPreprocessors, ...appendPreprocessors];
|
|
991
|
-
} else if (Array.isArray(options.preprocess)) {
|
|
992
|
-
options.preprocess.unshift(...prependPreprocessors);
|
|
993
|
-
options.preprocess.push(...appendPreprocessors);
|
|
994
|
-
} else {
|
|
995
|
-
options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
const generateMissingSourceMaps = !!options.experimental?.generateMissingPreprocessorSourcemaps;
|
|
999
|
-
if (options.preprocess && generateMissingSourceMaps) {
|
|
1000
|
-
options.preprocess = Array.isArray(options.preprocess) ? options.preprocess.map((p, i) => validateSourceMapOutputWrapper(p, i)) : validateSourceMapOutputWrapper(options.preprocess, 0);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
function validateSourceMapOutputWrapper(group, i) {
|
|
1004
|
-
const wrapper = {};
|
|
1005
|
-
for (const [processorType, processorFn] of Object.entries(group)) {
|
|
1006
|
-
wrapper[processorType] = async (options) => {
|
|
1007
|
-
const result = await processorFn(options);
|
|
1008
|
-
if (result && result.code !== options.content) {
|
|
1009
|
-
let invalidMap = false;
|
|
1010
|
-
if (!result.map) {
|
|
1011
|
-
invalidMap = true;
|
|
1012
|
-
log.warn.enabled && log.warn.once(
|
|
1013
|
-
`preprocessor at index ${i} did not return a sourcemap for ${processorType} transform`,
|
|
1014
|
-
{
|
|
1015
|
-
filename: options.filename,
|
|
1016
|
-
type: processorType,
|
|
1017
|
-
processor: processorFn.toString()
|
|
1018
|
-
}
|
|
1019
|
-
);
|
|
1020
|
-
} else if (result.map?.mappings === "") {
|
|
1021
|
-
invalidMap = true;
|
|
1022
|
-
log.warn.enabled && log.warn.once(
|
|
1023
|
-
`preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
|
|
1024
|
-
{
|
|
1025
|
-
filename: options.filename,
|
|
1026
|
-
type: processorType,
|
|
1027
|
-
processor: processorFn.toString()
|
|
1028
|
-
}
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
if (invalidMap) {
|
|
1032
|
-
try {
|
|
1033
|
-
const map = await buildSourceMap(options.content, result.code, options.filename);
|
|
1034
|
-
if (map) {
|
|
1035
|
-
log.debug.enabled && log.debug(
|
|
1036
|
-
`adding generated sourcemap to preprocesor result for ${options.filename}`
|
|
1037
|
-
);
|
|
1038
|
-
result.map = map;
|
|
1039
|
-
}
|
|
1040
|
-
} catch (e) {
|
|
1041
|
-
log.error(`failed to build sourcemap`, e);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
return result;
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
return wrapper;
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
1054
|
// src/utils/options.ts
|
|
1052
1055
|
var import_deepmerge = __toESM(require("deepmerge"), 1);
|
|
1053
1056
|
var import_vitefu3 = require("vitefu");
|
|
1054
1057
|
|
|
1055
1058
|
// src/utils/dependencies.ts
|
|
1056
|
-
var
|
|
1059
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
1057
1060
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
1058
1061
|
var import_vitefu = require("vitefu");
|
|
1059
1062
|
async function resolveDependencyData(dep, parent) {
|
|
@@ -1062,7 +1065,7 @@ async function resolveDependencyData(dep, parent) {
|
|
|
1062
1065
|
return void 0;
|
|
1063
1066
|
try {
|
|
1064
1067
|
return {
|
|
1065
|
-
dir:
|
|
1068
|
+
dir: import_path5.default.dirname(depDataPath),
|
|
1066
1069
|
pkg: JSON.parse(await import_promises.default.readFile(depDataPath, "utf-8"))
|
|
1067
1070
|
};
|
|
1068
1071
|
} catch {
|
|
@@ -1117,7 +1120,9 @@ function isCommonDepWithoutSvelteField(dependency) {
|
|
|
1117
1120
|
// src/utils/vite-plugin-svelte-stats.ts
|
|
1118
1121
|
var import_vitefu2 = require("vitefu");
|
|
1119
1122
|
var import_fs3 = require("fs");
|
|
1123
|
+
var import_path6 = require("path");
|
|
1120
1124
|
var import_perf_hooks = require("perf_hooks");
|
|
1125
|
+
var import_vite3 = require("vite");
|
|
1121
1126
|
var defaultCollectionOptions = {
|
|
1122
1127
|
logInProgress: (c, now) => now - c.collectionStart > 500 && c.stats.length > 1,
|
|
1123
1128
|
logResult: () => true
|
|
@@ -1155,6 +1160,19 @@ function formatPackageStats(pkgStats) {
|
|
|
1155
1160
|
).join("\n");
|
|
1156
1161
|
return table;
|
|
1157
1162
|
}
|
|
1163
|
+
async function getClosestNamedPackage(file) {
|
|
1164
|
+
let name = "$unknown";
|
|
1165
|
+
let path11 = await (0, import_vitefu2.findClosestPkgJsonPath)(file, (pkgPath) => {
|
|
1166
|
+
const pkg = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8"));
|
|
1167
|
+
if (pkg.name != null) {
|
|
1168
|
+
name = pkg.name;
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
return false;
|
|
1172
|
+
});
|
|
1173
|
+
path11 = (0, import_vite3.normalizePath)((0, import_path6.dirname)(path11 ?? file)) + "/";
|
|
1174
|
+
return { name, path: path11 };
|
|
1175
|
+
}
|
|
1158
1176
|
var VitePluginSvelteStats = class {
|
|
1159
1177
|
constructor() {
|
|
1160
1178
|
this._packages = [];
|
|
@@ -1179,6 +1197,7 @@ var VitePluginSvelteStats = class {
|
|
|
1179
1197
|
if (collection.finished) {
|
|
1180
1198
|
throw new Error("called after finish() has been used");
|
|
1181
1199
|
}
|
|
1200
|
+
file = (0, import_vite3.normalizePath)(file);
|
|
1182
1201
|
const start = import_perf_hooks.performance.now();
|
|
1183
1202
|
const stat = { file, start, end: start };
|
|
1184
1203
|
return () => {
|
|
@@ -1202,50 +1221,40 @@ var VitePluginSvelteStats = class {
|
|
|
1202
1221
|
await Promise.all(this._collections.map((c) => c.finish()));
|
|
1203
1222
|
}
|
|
1204
1223
|
async _finish(collection) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
collection.packageStats
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1224
|
+
try {
|
|
1225
|
+
collection.finished = true;
|
|
1226
|
+
const now = import_perf_hooks.performance.now();
|
|
1227
|
+
collection.duration = now - collection.collectionStart;
|
|
1228
|
+
const logResult = collection.options.logResult(collection);
|
|
1229
|
+
if (logResult) {
|
|
1230
|
+
await this._aggregateStatsResult(collection);
|
|
1231
|
+
log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats));
|
|
1232
|
+
}
|
|
1233
|
+
const index = this._collections.indexOf(collection);
|
|
1234
|
+
this._collections.splice(index, 1);
|
|
1235
|
+
collection.stats.length = 0;
|
|
1236
|
+
collection.stats = [];
|
|
1237
|
+
if (collection.packageStats) {
|
|
1238
|
+
collection.packageStats.length = 0;
|
|
1239
|
+
collection.packageStats = [];
|
|
1240
|
+
}
|
|
1241
|
+
collection.start = () => () => {
|
|
1242
|
+
};
|
|
1243
|
+
collection.finish = () => {
|
|
1244
|
+
};
|
|
1245
|
+
} catch (e) {
|
|
1246
|
+
log.debug.once(`failed to finish stats for ${collection.name}`, e);
|
|
1247
|
+
}
|
|
1225
1248
|
}
|
|
1226
1249
|
async _aggregateStatsResult(collection) {
|
|
1227
1250
|
const stats = collection.stats;
|
|
1228
1251
|
for (const stat of stats) {
|
|
1229
1252
|
let pkg = this._packages.find((p) => stat.file.startsWith(p.path));
|
|
1230
1253
|
if (!pkg) {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
let path9 = pkgPath?.replace(/package.json$/, "");
|
|
1234
|
-
let name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
|
|
1235
|
-
if (!name) {
|
|
1236
|
-
pkgPath = await (0, import_vitefu2.findClosestPkgJsonPath)(path9);
|
|
1237
|
-
if (pkgPath) {
|
|
1238
|
-
path9 = pkgPath?.replace(/package.json$/, "");
|
|
1239
|
-
name = JSON.parse((0, import_fs3.readFileSync)(pkgPath, "utf-8")).name;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
if (path9 && name) {
|
|
1243
|
-
pkg = { path: path9, name };
|
|
1244
|
-
this._packages.push(pkg);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1254
|
+
pkg = await getClosestNamedPackage(stat.file);
|
|
1255
|
+
this._packages.push(pkg);
|
|
1247
1256
|
}
|
|
1248
|
-
stat.pkg = pkg
|
|
1257
|
+
stat.pkg = pkg.name;
|
|
1249
1258
|
}
|
|
1250
1259
|
const grouped = {};
|
|
1251
1260
|
stats.forEach((stat) => {
|
|
@@ -1504,9 +1513,12 @@ function handleDeprecatedOptions(options) {
|
|
|
1504
1513
|
"experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries"
|
|
1505
1514
|
);
|
|
1506
1515
|
}
|
|
1516
|
+
if (options.experimental?.generateMissingPreprocessorSourcemaps) {
|
|
1517
|
+
log.warn("experimental.generateMissingPreprocessorSourcemaps has been removed.");
|
|
1518
|
+
}
|
|
1507
1519
|
}
|
|
1508
1520
|
function resolveViteRoot(viteConfig) {
|
|
1509
|
-
return (0,
|
|
1521
|
+
return (0, import_vite4.normalizePath)(viteConfig.root ? import_path7.default.resolve(viteConfig.root) : process.cwd());
|
|
1510
1522
|
}
|
|
1511
1523
|
async function buildExtraViteConfig(options, config) {
|
|
1512
1524
|
const extraViteConfig = {
|
|
@@ -1663,6 +1675,13 @@ function buildExtraConfigForSvelte(config) {
|
|
|
1663
1675
|
return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
|
|
1664
1676
|
}
|
|
1665
1677
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1678
|
+
if (options.preprocess) {
|
|
1679
|
+
for (const preprocessor of arraify(options.preprocess)) {
|
|
1680
|
+
if (preprocessor.style && "__resolvedConfig" in preprocessor.style) {
|
|
1681
|
+
preprocessor.style.__resolvedConfig = viteConfig;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1666
1685
|
const facadeEsbuildSveltePlugin = viteConfig.optimizeDeps.esbuildOptions?.plugins?.find(
|
|
1667
1686
|
(plugin) => plugin.name === facadeEsbuildSveltePluginName
|
|
1668
1687
|
);
|
|
@@ -1670,10 +1689,13 @@ function patchResolvedViteConfig(viteConfig, options) {
|
|
|
1670
1689
|
Object.assign(facadeEsbuildSveltePlugin, esbuildSveltePlugin(options));
|
|
1671
1690
|
}
|
|
1672
1691
|
}
|
|
1692
|
+
function arraify(value) {
|
|
1693
|
+
return Array.isArray(value) ? value : [value];
|
|
1694
|
+
}
|
|
1673
1695
|
|
|
1674
1696
|
// src/utils/watch.ts
|
|
1675
1697
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
1676
|
-
var
|
|
1698
|
+
var import_path8 = __toESM(require("path"), 1);
|
|
1677
1699
|
function setupWatchers(options, cache, requestParser) {
|
|
1678
1700
|
const { server, configFile: svelteConfigFile } = options;
|
|
1679
1701
|
if (!server) {
|
|
@@ -1720,7 +1742,7 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1720
1742
|
unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
|
|
1721
1743
|
};
|
|
1722
1744
|
if (svelteConfigFile !== false) {
|
|
1723
|
-
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) =>
|
|
1745
|
+
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path8.default.join(root, cfg));
|
|
1724
1746
|
const restartOnConfigAdd = (filename) => {
|
|
1725
1747
|
if (possibleSvelteConfigs.includes(filename)) {
|
|
1726
1748
|
triggerViteRestart(filename);
|
|
@@ -1746,12 +1768,12 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1746
1768
|
}
|
|
1747
1769
|
function ensureWatchedFile(watcher, file, root) {
|
|
1748
1770
|
if (file && !file.startsWith(root + "/") && !file.includes("\0") && import_fs4.default.existsSync(file)) {
|
|
1749
|
-
watcher.add(
|
|
1771
|
+
watcher.add(import_path8.default.resolve(file));
|
|
1750
1772
|
}
|
|
1751
1773
|
}
|
|
1752
1774
|
|
|
1753
1775
|
// src/utils/resolve.ts
|
|
1754
|
-
var
|
|
1776
|
+
var import_path9 = __toESM(require("path"), 1);
|
|
1755
1777
|
var import_module2 = require("module");
|
|
1756
1778
|
async function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
1757
1779
|
if (importer && isBareImport(importee) && !isNodeInternal(importee) && !isCommonDepWithoutSvelteField(importee)) {
|
|
@@ -1763,7 +1785,7 @@ async function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
|
1763
1785
|
if (pkgData) {
|
|
1764
1786
|
const { pkg, dir } = pkgData;
|
|
1765
1787
|
if (pkg.svelte) {
|
|
1766
|
-
const result =
|
|
1788
|
+
const result = import_path9.default.resolve(dir, pkg.svelte);
|
|
1767
1789
|
cache.setResolvedSvelteField(importee, importer, result);
|
|
1768
1790
|
return result;
|
|
1769
1791
|
}
|
|
@@ -1774,7 +1796,7 @@ function isNodeInternal(importee) {
|
|
|
1774
1796
|
return importee.startsWith("node:") || import_module2.builtinModules.includes(importee);
|
|
1775
1797
|
}
|
|
1776
1798
|
function isBareImport(importee) {
|
|
1777
|
-
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") ||
|
|
1799
|
+
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path9.default.isAbsolute(importee)) {
|
|
1778
1800
|
return false;
|
|
1779
1801
|
}
|
|
1780
1802
|
const parts = importee.split("/");
|
|
@@ -1790,7 +1812,7 @@ function isBareImport(importee) {
|
|
|
1790
1812
|
|
|
1791
1813
|
// src/utils/optimizer.ts
|
|
1792
1814
|
var import_fs5 = require("fs");
|
|
1793
|
-
var
|
|
1815
|
+
var import_path10 = __toESM(require("path"), 1);
|
|
1794
1816
|
var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
1795
1817
|
"compilerOptions",
|
|
1796
1818
|
"configFile",
|
|
@@ -1801,7 +1823,7 @@ var PREBUNDLE_SENSITIVE_OPTIONS = [
|
|
|
1801
1823
|
];
|
|
1802
1824
|
async function saveSvelteMetadata(cacheDir, options) {
|
|
1803
1825
|
const svelteMetadata = generateSvelteMetadata(options);
|
|
1804
|
-
const svelteMetadataPath =
|
|
1826
|
+
const svelteMetadataPath = import_path10.default.resolve(cacheDir, "_svelte_metadata.json");
|
|
1805
1827
|
const currentSvelteMetadata = JSON.stringify(svelteMetadata, (_, value) => {
|
|
1806
1828
|
return typeof value === "function" ? value.toString() : value;
|
|
1807
1829
|
});
|
|
@@ -1823,8 +1845,8 @@ function generateSvelteMetadata(options) {
|
|
|
1823
1845
|
}
|
|
1824
1846
|
|
|
1825
1847
|
// src/ui/inspector/plugin.ts
|
|
1826
|
-
var
|
|
1827
|
-
var
|
|
1848
|
+
var import_vite5 = require("vite");
|
|
1849
|
+
var import_path11 = __toESM(require("path"), 1);
|
|
1828
1850
|
var import_url2 = require("url");
|
|
1829
1851
|
var import_fs6 = __toESM(require("fs"), 1);
|
|
1830
1852
|
|
|
@@ -1851,7 +1873,7 @@ var defaultInspectorOptions = {
|
|
|
1851
1873
|
customStyles: true
|
|
1852
1874
|
};
|
|
1853
1875
|
function getInspectorPath() {
|
|
1854
|
-
const pluginPath = (0,
|
|
1876
|
+
const pluginPath = (0, import_vite5.normalizePath)(import_path11.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
|
|
1855
1877
|
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1856
1878
|
}
|
|
1857
1879
|
function svelteInspector() {
|
|
@@ -1877,7 +1899,7 @@ function svelteInspector() {
|
|
|
1877
1899
|
disabled = true;
|
|
1878
1900
|
} else {
|
|
1879
1901
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1880
|
-
const out_dir =
|
|
1902
|
+
const out_dir = import_path11.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
|
|
1881
1903
|
inspectorOptions.appendTo = `${out_dir}/generated/root.svelte`;
|
|
1882
1904
|
}
|
|
1883
1905
|
appendTo = inspectorOptions.appendTo;
|
|
@@ -2027,8 +2049,8 @@ var VitePluginSvelteCache = class {
|
|
|
2027
2049
|
getError(svelteRequest) {
|
|
2028
2050
|
return this._errors.get(svelteRequest.normalizedFilename);
|
|
2029
2051
|
}
|
|
2030
|
-
getDependants(
|
|
2031
|
-
const dependants = this._dependants.get(
|
|
2052
|
+
getDependants(path11) {
|
|
2053
|
+
const dependants = this._dependants.get(path11);
|
|
2032
2054
|
return dependants ? [...dependants] : [];
|
|
2033
2055
|
}
|
|
2034
2056
|
getResolvedSvelteField(name, importer) {
|
|
@@ -2045,6 +2067,97 @@ var VitePluginSvelteCache = class {
|
|
|
2045
2067
|
}
|
|
2046
2068
|
};
|
|
2047
2069
|
|
|
2070
|
+
// src/utils/load-raw.ts
|
|
2071
|
+
var import_fs7 = __toESM(require("fs"), 1);
|
|
2072
|
+
async function loadRaw(svelteRequest, compileSvelte2, options) {
|
|
2073
|
+
const { id, filename, query } = svelteRequest;
|
|
2074
|
+
let compileData;
|
|
2075
|
+
const source = import_fs7.default.readFileSync(filename, "utf-8");
|
|
2076
|
+
try {
|
|
2077
|
+
svelteRequest.ssr = query.compilerOptions?.generate === "ssr";
|
|
2078
|
+
const type = query.type;
|
|
2079
|
+
compileData = await compileSvelte2(svelteRequest, source, {
|
|
2080
|
+
...options,
|
|
2081
|
+
compilerOptions: {
|
|
2082
|
+
dev: false,
|
|
2083
|
+
css: false,
|
|
2084
|
+
hydratable: false,
|
|
2085
|
+
enableSourcemap: query.sourcemap ? {
|
|
2086
|
+
js: type === "script" || type === "all",
|
|
2087
|
+
css: type === "style" || type === "all"
|
|
2088
|
+
} : false,
|
|
2089
|
+
...svelteRequest.query.compilerOptions
|
|
2090
|
+
},
|
|
2091
|
+
hot: false,
|
|
2092
|
+
emitCss: true
|
|
2093
|
+
});
|
|
2094
|
+
} catch (e) {
|
|
2095
|
+
throw toRollupError(e, options);
|
|
2096
|
+
}
|
|
2097
|
+
let result;
|
|
2098
|
+
if (query.type === "style") {
|
|
2099
|
+
result = compileData.compiled.css;
|
|
2100
|
+
} else if (query.type === "script") {
|
|
2101
|
+
result = compileData.compiled.js;
|
|
2102
|
+
} else if (query.type === "preprocessed") {
|
|
2103
|
+
result = compileData.preprocessed;
|
|
2104
|
+
} else if (query.type === "all" && query.raw) {
|
|
2105
|
+
return allToRawExports(compileData, source);
|
|
2106
|
+
} else {
|
|
2107
|
+
throw new Error(
|
|
2108
|
+
`invalid "type=${query.type}" in ${id}. supported are script, style, preprocessed, all`
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
if (query.direct) {
|
|
2112
|
+
const supportedDirectTypes = ["script", "style"];
|
|
2113
|
+
if (!supportedDirectTypes.includes(query.type)) {
|
|
2114
|
+
throw new Error(
|
|
2115
|
+
`invalid "type=${query.type}" combined with direct in ${id}. supported are: ${supportedDirectTypes.join(", ")}`
|
|
2116
|
+
);
|
|
2117
|
+
}
|
|
2118
|
+
log.debug(`load returns direct result for ${id}`);
|
|
2119
|
+
let directOutput = result.code;
|
|
2120
|
+
if (query.sourcemap && result.map?.toUrl) {
|
|
2121
|
+
const map = `sourceMappingURL=${result.map.toUrl()}`;
|
|
2122
|
+
if (query.type === "style") {
|
|
2123
|
+
directOutput += `
|
|
2124
|
+
|
|
2125
|
+
/*# ${map} */
|
|
2126
|
+
`;
|
|
2127
|
+
} else if (query.type === "script") {
|
|
2128
|
+
directOutput += `
|
|
2129
|
+
|
|
2130
|
+
//# ${map}
|
|
2131
|
+
`;
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return directOutput;
|
|
2135
|
+
} else if (query.raw) {
|
|
2136
|
+
log.debug(`load returns raw result for ${id}`);
|
|
2137
|
+
return toRawExports(result);
|
|
2138
|
+
} else {
|
|
2139
|
+
throw new Error(`invalid raw mode in ${id}, supported are raw, direct`);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
function allToRawExports(compileData, source) {
|
|
2143
|
+
const exports = {
|
|
2144
|
+
...compileData,
|
|
2145
|
+
...compileData.compiled,
|
|
2146
|
+
source
|
|
2147
|
+
};
|
|
2148
|
+
delete exports.compiled;
|
|
2149
|
+
delete exports.filename;
|
|
2150
|
+
return toRawExports(exports);
|
|
2151
|
+
}
|
|
2152
|
+
function toRawExports(object) {
|
|
2153
|
+
let exports = Object.entries(object).filter(([key, value]) => typeof value !== "function").sort(([a], [b]) => a < b ? -1 : a === b ? 0 : 1).map(([key, value]) => `export const ${key}=${JSON.stringify(value)}`).join("\n") + "\n";
|
|
2154
|
+
if (Object.prototype.hasOwnProperty.call(object, "code")) {
|
|
2155
|
+
exports += `export default code
|
|
2156
|
+
`;
|
|
2157
|
+
}
|
|
2158
|
+
return exports;
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2048
2161
|
// src/index.ts
|
|
2049
2162
|
function svelte(inlineOptions) {
|
|
2050
2163
|
if (process.env.DEBUG != null) {
|
|
@@ -2095,21 +2208,25 @@ function svelte(inlineOptions) {
|
|
|
2095
2208
|
options.server = server;
|
|
2096
2209
|
setupWatchers(options, cache, requestParser);
|
|
2097
2210
|
},
|
|
2098
|
-
load(id, opts) {
|
|
2211
|
+
async load(id, opts) {
|
|
2099
2212
|
const ssr = !!opts?.ssr;
|
|
2100
2213
|
const svelteRequest = requestParser(id, !!ssr);
|
|
2101
2214
|
if (svelteRequest) {
|
|
2102
|
-
const { filename, query } = svelteRequest;
|
|
2103
|
-
if (
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2215
|
+
const { filename, query, raw } = svelteRequest;
|
|
2216
|
+
if (raw) {
|
|
2217
|
+
return loadRaw(svelteRequest, compileSvelte2, options);
|
|
2218
|
+
} else {
|
|
2219
|
+
if (query.svelte && query.type === "style") {
|
|
2220
|
+
const css = cache.getCSS(svelteRequest);
|
|
2221
|
+
if (css) {
|
|
2222
|
+
log.debug(`load returns css for ${filename}`);
|
|
2223
|
+
return css;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
if (viteConfig.assetsInclude(filename)) {
|
|
2227
|
+
log.debug(`load returns raw content for ${filename}`);
|
|
2228
|
+
return import_fs8.default.readFileSync(filename, "utf-8");
|
|
2108
2229
|
}
|
|
2109
|
-
}
|
|
2110
|
-
if (viteConfig.assetsInclude(filename)) {
|
|
2111
|
-
log.debug(`load returns raw content for ${filename}`);
|
|
2112
|
-
return import_fs7.default.readFileSync(filename, "utf-8");
|
|
2113
2230
|
}
|
|
2114
2231
|
}
|
|
2115
2232
|
},
|
|
@@ -2117,12 +2234,10 @@ function svelte(inlineOptions) {
|
|
|
2117
2234
|
const ssr = !!opts?.ssr;
|
|
2118
2235
|
const svelteRequest = requestParser(importee, ssr);
|
|
2119
2236
|
if (svelteRequest?.query.svelte) {
|
|
2120
|
-
if (svelteRequest.query.type === "style") {
|
|
2237
|
+
if (svelteRequest.query.type === "style" && !svelteRequest.raw) {
|
|
2121
2238
|
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
2122
2239
|
return svelteRequest.cssId;
|
|
2123
2240
|
}
|
|
2124
|
-
log.debug(`resolveId resolved ${importee}`);
|
|
2125
|
-
return importee;
|
|
2126
2241
|
}
|
|
2127
2242
|
if (ssr && importee === "svelte") {
|
|
2128
2243
|
if (!resolvedSvelteSSR) {
|
|
@@ -2164,7 +2279,7 @@ function svelte(inlineOptions) {
|
|
|
2164
2279
|
async transform(code, id, opts) {
|
|
2165
2280
|
const ssr = !!opts?.ssr;
|
|
2166
2281
|
const svelteRequest = requestParser(id, ssr);
|
|
2167
|
-
if (!svelteRequest || svelteRequest.query.
|
|
2282
|
+
if (!svelteRequest || svelteRequest.query.type === "style" || svelteRequest.raw) {
|
|
2168
2283
|
return;
|
|
2169
2284
|
}
|
|
2170
2285
|
let compileData;
|
|
@@ -2215,6 +2330,7 @@ function svelte(inlineOptions) {
|
|
|
2215
2330
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2216
2331
|
0 && (module.exports = {
|
|
2217
2332
|
loadSvelteConfig,
|
|
2218
|
-
svelte
|
|
2333
|
+
svelte,
|
|
2334
|
+
vitePreprocess
|
|
2219
2335
|
});
|
|
2220
2336
|
//# sourceMappingURL=index.cjs.map
|