@sveltejs/vite-plugin-svelte 4.0.0-next.1 → 4.0.0-next.2

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": "4.0.0-next.1",
3
+ "version": "4.0.0-next.2",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -36,12 +36,12 @@
36
36
  },
37
37
  "homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
38
38
  "dependencies": {
39
+ "@sveltejs/vite-plugin-svelte-inspector": "^3.0.0-next.0||^3.0.0",
39
40
  "debug": "^4.3.4",
40
41
  "deepmerge": "^4.3.1",
41
42
  "kleur": "^4.1.5",
42
43
  "magic-string": "^0.30.10",
43
- "vitefu": "^0.2.5",
44
- "@sveltejs/vite-plugin-svelte-inspector": "^3.0.0-next.1"
44
+ "vitefu": "^0.2.5"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "svelte": "^5.0.0-next.96 || ^5.0.0",
@@ -49,9 +49,9 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/debug": "^4.1.12",
52
- "esbuild": "^0.20.2",
53
- "sass": "^1.76.0",
54
- "svelte": "^5.0.0-next.123",
52
+ "esbuild": "^0.21.3",
53
+ "sass": "^1.77.2",
54
+ "svelte": "^5.0.0-next.141",
55
55
  "vite": "^5.2.11"
56
56
  },
57
57
  "scripts": {
package/src/preprocess.js CHANGED
@@ -61,29 +61,16 @@ function viteScript() {
61
61
  * @returns {{ style: import('svelte/compiler').Preprocessor }}
62
62
  */
63
63
  function viteStyle(config = {}) {
64
- /** @type {CssTransform} */
65
- let transform;
64
+ /** @type {Promise<CssTransform> | CssTransform} */
65
+ let cssTransform;
66
66
  /** @type {import('svelte/compiler').Preprocessor} */
67
67
  const style = async ({ attributes, content, filename = '' }) => {
68
68
  const ext = attributes.lang ? `.${attributes.lang}` : '.css';
69
69
  if (attributes.lang && !isCSSRequest(ext)) return;
70
- if (!transform) {
71
- /** @type {import('vite').ResolvedConfig} */
72
- let resolvedConfig;
73
- // @ts-expect-error special prop added if running in v-p-s
74
- if (style.__resolvedConfig) {
75
- // @ts-expect-error
76
- resolvedConfig = style.__resolvedConfig;
77
- } else if (isResolvedConfig(config)) {
78
- resolvedConfig = config;
79
- } else {
80
- resolvedConfig = await resolveConfig(
81
- config,
82
- process.env.NODE_ENV === 'production' ? 'build' : 'serve'
83
- );
84
- }
85
- transform = getCssTransformFn(resolvedConfig);
70
+ if (!cssTransform) {
71
+ cssTransform = createCssTransform(style, config).then((t) => (cssTransform = t));
86
72
  }
73
+ const transform = await cssTransform;
87
74
  const suffix = `${lang_sep}${ext}`;
88
75
  const moduleId = `${filename}${suffix}`;
89
76
  const { code, map, deps } = await transform(content, moduleId);
@@ -102,12 +89,27 @@ function viteStyle(config = {}) {
102
89
  }
103
90
 
104
91
  /**
105
- * @param {import('vite').ResolvedConfig} config
106
- * @returns {CssTransform}
92
+ * @param {import('svelte/compiler').Preprocessor} style
93
+ * @param {import('vite').ResolvedConfig | import('vite').InlineConfig} config
94
+ * @returns {Promise<CssTransform>}
107
95
  */
108
- function getCssTransformFn(config) {
96
+ async function createCssTransform(style, config) {
97
+ /** @type {import('vite').ResolvedConfig} */
98
+ let resolvedConfig;
99
+ // @ts-expect-error special prop added if running in v-p-s
100
+ if (style.__resolvedConfig) {
101
+ // @ts-expect-error
102
+ resolvedConfig = style.__resolvedConfig;
103
+ } else if (isResolvedConfig(config)) {
104
+ resolvedConfig = config;
105
+ } else {
106
+ resolvedConfig = await resolveConfig(
107
+ config,
108
+ process.env.NODE_ENV === 'production' ? 'build' : 'serve'
109
+ );
110
+ }
109
111
  return async (code, filename) => {
110
- return preprocessCSS(code, filename, config);
112
+ return preprocessCSS(code, filename, resolvedConfig);
111
113
  };
112
114
  }
113
115
 
package/src/public.d.ts CHANGED
@@ -204,5 +204,5 @@ export interface VitePreprocessOptions {
204
204
  */
205
205
  style?: boolean | InlineConfig | ResolvedConfig;
206
206
  }
207
-
207
+ // eslint-disable-next-line n/no-missing-import
208
208
  export * from './index.js';
@@ -1,5 +1,6 @@
1
1
  import type { CompileOptions } from 'svelte/compiler';
2
2
  import type { ViteDevServer } from 'vite';
3
+ // eslint-disable-next-line n/no-missing-import
3
4
  import { VitePluginSvelteStats } from '../utils/vite-plugin-svelte-stats.js';
4
5
  import type { Options } from '../public.d.ts';
5
6
 
@@ -201,7 +201,11 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
201
201
  compilerOptions: {
202
202
  css,
203
203
  dev: !viteConfig.isProduction,
204
- hmr: !viteConfig.isProduction && !preResolveOptions.isBuild
204
+ hmr:
205
+ !viteConfig.isProduction &&
206
+ !preResolveOptions.isBuild &&
207
+ viteConfig.server &&
208
+ viteConfig.server.hmr !== false
205
209
  }
206
210
  };
207
211
 
@@ -217,7 +221,7 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
217
221
  removeIgnoredOptions(merged);
218
222
  handleDeprecatedOptions(merged);
219
223
  addExtraPreprocessors(merged, viteConfig);
220
- enforceOptionsForHmr(merged);
224
+ enforceOptionsForHmr(merged, viteConfig);
221
225
  enforceOptionsForProduction(merged);
222
226
  // mergeConfigs would mangle functions on the stats class, so do this afterwards
223
227
  if (log.debug.enabled && isDebugNamespaceEnabled('stats')) {
@@ -228,8 +232,9 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
228
232
 
229
233
  /**
230
234
  * @param {import('../types/options.d.ts').ResolvedOptions} options
235
+ * @param {import('vite').ResolvedConfig} viteConfig
231
236
  */
232
- function enforceOptionsForHmr(options) {
237
+ function enforceOptionsForHmr(options, viteConfig) {
233
238
  if (options.hot) {
234
239
  log.warn(
235
240
  'svelte 5 has hmr integrated in core. Please remove the vitePlugin.hot option and use compilerOptions.hmr instead'
@@ -237,6 +242,12 @@ function enforceOptionsForHmr(options) {
237
242
  delete options.hot;
238
243
  options.compilerOptions.hmr = true;
239
244
  }
245
+ if (options.compilerOptions.hmr && viteConfig.server?.hmr === false) {
246
+ log.warn(
247
+ 'vite config server.hmr is false but compilerOptions.hmr is true. Forcing compilerOptions.hmr to false as it would not work.'
248
+ );
249
+ options.compilerOptions.hmr = false;
250
+ }
240
251
  }
241
252
 
242
253
  /**
@@ -264,7 +275,7 @@ function enforceOptionsForProduction(options) {
264
275
  */
265
276
  function removeIgnoredOptions(options) {
266
277
  const ignoredCompilerOptions = ['generate', 'format', 'filename'];
267
- if (options.hot && options.emitCss) {
278
+ if (options.compilerOptions.hmr && options.emitCss) {
268
279
  ignoredCompilerOptions.push('cssHash');
269
280
  }
270
281
  const passedCompilerOptions = Object.keys(options.compilerOptions || {});