@sveltejs/vite-plugin-svelte 2.0.0-beta.2 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/vite-plugin-svelte",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -46,15 +46,15 @@
46
46
  },
47
47
  "peerDependencies": {
48
48
  "svelte": "^3.54.0",
49
- "vite": "^4.0.0-beta.5"
49
+ "vite": "^4.0.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/debug": "^4.1.7",
53
- "esbuild": "^0.16.1",
53
+ "esbuild": "^0.16.3",
54
54
  "rollup": "^2.79.1",
55
55
  "svelte": "^3.54.0",
56
56
  "tsup": "^6.5.0",
57
- "vite": "^4.0.0-beta.5"
57
+ "vite": "^4.0.0"
58
58
  },
59
59
  "scripts": {
60
60
  "dev": "pnpm build:ci --sourcemap --watch src",
package/src/index.ts CHANGED
@@ -89,7 +89,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
89
89
  if (isSvelteMetadataChanged) {
90
90
  // Force Vite to optimize again. Although we mutate the config here, it works because
91
91
  // Vite's optimizer runs after `buildStart()`.
92
- // TODO: verify this works in vite3
93
92
  viteConfig.optimizeDeps.force = true;
94
93
  }
95
94
  },
package/src/preprocess.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
- import * as vite from 'vite';
3
- import type { ESBuildOptions, ResolvedConfig } from 'vite';
2
+ import { preprocessCSS, resolveConfig, transformWithEsbuild } from 'vite';
3
+ import type { ESBuildOptions, InlineConfig, ResolvedConfig } from 'vite';
4
4
  // eslint-disable-next-line node/no-missing-import
5
5
  import type { Preprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess';
6
6
 
@@ -9,7 +9,7 @@ const supportedScriptLangs = ['ts'];
9
9
 
10
10
  export function vitePreprocess(opts?: {
11
11
  script?: boolean;
12
- style?: boolean | vite.InlineConfig | vite.ResolvedConfig;
12
+ style?: boolean | InlineConfig | ResolvedConfig;
13
13
  }) {
14
14
  const preprocessor: PreprocessorGroup = {};
15
15
  if (opts?.script !== false) {
@@ -27,7 +27,7 @@ function viteScript(): { script: Preprocessor } {
27
27
  async script({ attributes, content, filename = '' }) {
28
28
  const lang = attributes.lang as string;
29
29
  if (!supportedScriptLangs.includes(lang)) return;
30
- const transformResult = await vite.transformWithEsbuild(content, filename, {
30
+ const transformResult = await transformWithEsbuild(content, filename, {
31
31
  loader: lang as ESBuildOptions['loader'],
32
32
  target: 'esnext',
33
33
  tsconfigRaw: {
@@ -46,7 +46,7 @@ function viteScript(): { script: Preprocessor } {
46
46
  };
47
47
  }
48
48
 
49
- function viteStyle(config: vite.InlineConfig | vite.ResolvedConfig = {}): {
49
+ function viteStyle(config: InlineConfig | ResolvedConfig = {}): {
50
50
  style: Preprocessor;
51
51
  } {
52
52
  let transform: CssTransform;
@@ -54,7 +54,7 @@ function viteStyle(config: vite.InlineConfig | vite.ResolvedConfig = {}): {
54
54
  const lang = attributes.lang as string;
55
55
  if (!supportedStyleLangs.includes(lang)) return;
56
56
  if (!transform) {
57
- let resolvedConfig: vite.ResolvedConfig;
57
+ let resolvedConfig: ResolvedConfig;
58
58
  // @ts-expect-error special prop added if running in v-p-s
59
59
  if (style.__resolvedConfig) {
60
60
  // @ts-expect-error
@@ -62,7 +62,7 @@ function viteStyle(config: vite.InlineConfig | vite.ResolvedConfig = {}): {
62
62
  } else if (isResolvedConfig(config)) {
63
63
  resolvedConfig = config;
64
64
  } else {
65
- resolvedConfig = await vite.resolveConfig(
65
+ resolvedConfig = await resolveConfig(
66
66
  config,
67
67
  process.env.NODE_ENV === 'production' ? 'build' : 'serve'
68
68
  );
@@ -89,26 +89,11 @@ function viteStyle(config: vite.InlineConfig | vite.ResolvedConfig = {}): {
89
89
  type CssTransform = (code: string, filename: string) => Promise<{ code: string; map?: any }>;
90
90
 
91
91
  function getCssTransformFn(config: ResolvedConfig): CssTransform {
92
- // API is only available in Vite 3.2 and above
93
- // TODO: Remove Vite plugin hack when bump peer dep to Vite 3.2
94
- if (vite.preprocessCSS) {
95
- return async (code, filename) => {
96
- return vite.preprocessCSS(code, filename, config);
97
- };
98
- } else {
99
- const pluginName = 'vite:css';
100
- const plugin = config.plugins.find((p) => p.name === pluginName);
101
- if (!plugin) {
102
- throw new Error(`failed to find plugin ${pluginName}`);
103
- }
104
- if (!plugin.transform) {
105
- throw new Error(`plugin ${pluginName} has no transform`);
106
- }
107
- // @ts-expect-error
108
- return plugin.transform.bind(null);
109
- }
92
+ return async (code, filename) => {
93
+ return preprocessCSS(code, filename, config);
94
+ };
110
95
  }
111
96
 
112
- function isResolvedConfig(config: any): config is vite.ResolvedConfig {
97
+ function isResolvedConfig(config: any): config is ResolvedConfig {
113
98
  return !!config.inlineConfig;
114
99
  }
@@ -680,15 +680,6 @@ export interface SvelteOptions {
680
680
  * These options are considered experimental and breaking changes to them can occur in any release
681
681
  */
682
682
  export interface ExperimentalOptions {
683
- /**
684
- * Use extra preprocessors that delegate style and TypeScript preprocessing to native Vite plugins
685
- *
686
- * Do not use together with `svelte-preprocess`!
687
- *
688
- * @default false
689
- */
690
- useVitePreprocess?: boolean;
691
-
692
683
  /**
693
684
  * A function to update `compilerOptions` before compilation
694
685
  *
@@ -1,18 +1,8 @@
1
1
  import type { ResolvedConfig, Plugin } from 'vite';
2
2
  import MagicString from 'magic-string';
3
- import { preprocess } from 'svelte/compiler';
4
3
  import { PreprocessorGroup, ResolvedOptions } from './options';
5
4
  import { log } from './log';
6
5
  import path from 'path';
7
- import { vitePreprocess } from '../preprocess';
8
-
9
- function createVitePreprocessorGroup(config: ResolvedConfig): PreprocessorGroup {
10
- return {
11
- markup({ content, filename }) {
12
- return preprocess(content, vitePreprocess({ style: config }), { filename });
13
- }
14
- };
15
- }
16
6
 
17
7
  /**
18
8
  * this appends a *{} rule to component styles to force the svelte compiler to add style classes to all nodes
@@ -40,13 +30,6 @@ function buildExtraPreprocessors(options: ResolvedOptions, config: ResolvedConfi
40
30
  const prependPreprocessors: PreprocessorGroup[] = [];
41
31
  const appendPreprocessors: PreprocessorGroup[] = [];
42
32
 
43
- if (options.experimental?.useVitePreprocess) {
44
- log.warn(
45
- '`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.'
46
- );
47
- prependPreprocessors.push(createVitePreprocessorGroup(config));
48
- }
49
-
50
33
  // @ts-ignore
51
34
  const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
52
35
  if (pluginsWithPreprocessorsDeprecated.length > 0) {