@sveltejs/vite-plugin-svelte 1.4.0 → 2.0.0-beta.1

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.d.ts CHANGED
@@ -1,9 +1,9 @@
1
+ import * as vite from 'vite';
1
2
  import { UserConfig, Plugin } from 'vite';
2
3
  import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
3
4
  export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
4
5
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
5
6
  export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess';
6
- export { vitePreprocess } from './preprocess.js';
7
7
 
8
8
  type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline;
9
9
  interface PluginOptionsInline extends PluginOptions {
@@ -245,6 +245,11 @@ type ModuleFormat = NonNullable<CompileOptions['format']>;
245
245
  type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
246
246
  type Arrayable<T> = T | T[];
247
247
 
248
+ declare function vitePreprocess(opts?: {
249
+ script?: boolean;
250
+ style?: boolean | vite.InlineConfig | vite.ResolvedConfig;
251
+ }): PreprocessorGroup;
252
+
248
253
  declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<SvelteOptions> | undefined>;
249
254
 
250
255
  type SvelteWarningsMessage = {
@@ -259,4 +264,4 @@ type SvelteWarningsMessage = {
259
264
 
260
265
  declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
261
266
 
262
- export { Arrayable, CssHashGetter, ModuleFormat, Options, PluginOptions, SvelteOptions, SvelteWarningsMessage, loadSvelteConfig, svelte };
267
+ export { Arrayable, CssHashGetter, ModuleFormat, Options, PluginOptions, SvelteOptions, SvelteWarningsMessage, loadSvelteConfig, svelte, vitePreprocess };
package/dist/index.js CHANGED
@@ -915,38 +915,7 @@ function formatFrameForVite(frame) {
915
915
  return frame.split("\n").map((line) => line.match(/^\s+\^/) ? " " + line : " " + line.replace(":", " | ")).join("\n");
916
916
  }
917
917
 
918
- // src/utils/svelte-version.ts
919
- import { VERSION } from "svelte/compiler";
920
- var svelteVersion = parseVersion(VERSION);
921
- function parseVersion(version) {
922
- const segments = version.split(".", 3).map((s) => parseInt(s, 10));
923
- while (segments.length < 3) {
924
- segments.push(0);
925
- }
926
- return segments;
927
- }
928
- function compareToSvelte(version) {
929
- const parsedVersion = parseVersion(version);
930
- for (let i = 0; i < svelteVersion.length; i++) {
931
- const a = parsedVersion[i];
932
- const b = svelteVersion[i];
933
- if (a === b) {
934
- continue;
935
- } else if (a > b) {
936
- return 1;
937
- } else {
938
- return -1;
939
- }
940
- }
941
- return 0;
942
- }
943
- function atLeastSvelte(version) {
944
- const result = compareToSvelte(version) <= 0;
945
- return result;
946
- }
947
-
948
918
  // src/utils/esbuild.ts
949
- var isCssString = atLeastSvelte("3.53.0");
950
919
  var facadeEsbuildSveltePluginName = "vite-plugin-svelte:facade";
951
920
  function esbuildSveltePlugin(options) {
952
921
  return {
@@ -980,7 +949,7 @@ function esbuildSveltePlugin(options) {
980
949
  async function compileSvelte(options, { filename, code }, statsCollection) {
981
950
  let css = options.compilerOptions.css;
982
951
  if (css !== "none") {
983
- css = isCssString ? "injected" : true;
952
+ css = "injected";
984
953
  }
985
954
  const compileOptions = {
986
955
  ...options.compilerOptions,
@@ -1253,7 +1222,6 @@ var VitePluginSvelteStats = class {
1253
1222
  };
1254
1223
 
1255
1224
  // src/utils/options.ts
1256
- var cssAsString = atLeastSvelte("3.53.0");
1257
1225
  var allowedPluginOptions = /* @__PURE__ */ new Set([
1258
1226
  "include",
1259
1227
  "exclude",
@@ -1373,10 +1341,10 @@ function mergeConfigs(...configs) {
1373
1341
  return result;
1374
1342
  }
1375
1343
  function resolveOptions(preResolveOptions2, viteConfig) {
1376
- const css = cssAsString ? preResolveOptions2.emitCss ? "external" : "injected" : !preResolveOptions2.emitCss;
1344
+ const css = preResolveOptions2.emitCss ? "external" : "injected";
1377
1345
  const defaultOptions = {
1378
1346
  hot: viteConfig.isProduction ? false : {
1379
- injectCss: css === true || css === "injected",
1347
+ injectCss: css === "injected",
1380
1348
  partialAccept: !!viteConfig.experimental?.hmrPartialAccept
1381
1349
  },
1382
1350
  compilerOptions: {
@@ -1416,7 +1384,7 @@ function enforceOptionsForHmr(options) {
1416
1384
  }
1417
1385
  const css = options.compilerOptions.css;
1418
1386
  if (css === true || css === "injected") {
1419
- const forcedCss = cssAsString ? "external" : false;
1387
+ const forcedCss = "external";
1420
1388
  log.warn(
1421
1389
  `hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
1422
1390
  );
@@ -1435,7 +1403,7 @@ function enforceOptionsForHmr(options) {
1435
1403
  }
1436
1404
  const css = options.compilerOptions.css;
1437
1405
  if (!(css === true || css === "injected")) {
1438
- const forcedCss = cssAsString ? "injected" : true;
1406
+ const forcedCss = "injected";
1439
1407
  log.warn(
1440
1408
  `hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
1441
1409
  );
@@ -2145,7 +2113,6 @@ function svelte(inlineOptions) {
2145
2113
  let options;
2146
2114
  let viteConfig;
2147
2115
  let compileSvelte2;
2148
- let resolvedSvelteSSR;
2149
2116
  const api = {};
2150
2117
  const plugins = [
2151
2118
  {
@@ -2215,24 +2182,6 @@ function svelte(inlineOptions) {
2215
2182
  return svelteRequest.cssId;
2216
2183
  }
2217
2184
  }
2218
- if (ssr && importee === "svelte") {
2219
- if (!resolvedSvelteSSR) {
2220
- resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
2221
- (svelteSSR) => {
2222
- log.debug("resolved svelte to svelte/ssr");
2223
- return svelteSSR;
2224
- },
2225
- (err) => {
2226
- log.debug(
2227
- "failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it",
2228
- err
2229
- );
2230
- return null;
2231
- }
2232
- );
2233
- }
2234
- return resolvedSvelteSSR;
2235
- }
2236
2185
  const scan = !!opts?.scan;
2237
2186
  const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !isDepExcluded2(importee, viteConfig.optimizeDeps?.exclude ?? []);
2238
2187
  if (ssr || scan || !isPrebundled) {