@sveltejs/vite-plugin-svelte 3.1.0 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/vite-plugin-svelte",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -36,11 +36,11 @@
36
36
  },
37
37
  "homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
38
38
  "dependencies": {
39
- "@sveltejs/vite-plugin-svelte-inspector": "^2.0.0",
39
+ "@sveltejs/vite-plugin-svelte-inspector": "^2.1.0",
40
40
  "debug": "^4.3.4",
41
41
  "deepmerge": "^4.3.1",
42
42
  "kleur": "^4.1.5",
43
- "magic-string": "^0.30.9",
43
+ "magic-string": "^0.30.10",
44
44
  "svelte-hmr": "^0.16.0",
45
45
  "vitefu": "^0.2.5"
46
46
  },
@@ -51,9 +51,9 @@
51
51
  "devDependencies": {
52
52
  "@types/debug": "^4.1.12",
53
53
  "esbuild": "^0.20.2",
54
- "sass": "^1.74.1",
55
- "svelte": "^4.2.12",
56
- "vite": "^5.2.8"
54
+ "sass": "^1.75.0",
55
+ "svelte": "^4.2.15",
56
+ "vite": "^5.2.9"
57
57
  },
58
58
  "scripts": {
59
59
  "check:publint": "publint --strict",
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
 
@@ -199,13 +199,15 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
199
199
  dev: !viteConfig.isProduction
200
200
  }
201
201
  };
202
+ const hot =
203
+ !viteConfig.isProduction && !preResolveOptions.isBuild && viteConfig.server.hmr !== false;
202
204
  if (isSvelte5) {
203
205
  if (isSvelte5WithHMRSupport) {
204
206
  // @ts-expect-error svelte4 does not have hmr option
205
- defaultOptions.compilerOptions.hmr = !viteConfig.isProduction;
207
+ defaultOptions.compilerOptions.hmr = hot;
206
208
  }
207
209
  } else {
208
- defaultOptions.hot = viteConfig.isProduction
210
+ defaultOptions.hot = !hot
209
211
  ? false
210
212
  : {
211
213
  injectCss: css === 'injected',
@@ -224,7 +226,7 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
224
226
  removeIgnoredOptions(merged);
225
227
  handleDeprecatedOptions(merged);
226
228
  addExtraPreprocessors(merged, viteConfig);
227
- enforceOptionsForHmr(merged);
229
+ enforceOptionsForHmr(merged, viteConfig);
228
230
  enforceOptionsForProduction(merged);
229
231
  // mergeConfigs would mangle functions on the stats class, so do this afterwards
230
232
  if (log.debug.enabled && isDebugNamespaceEnabled('stats')) {
@@ -235,8 +237,15 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
235
237
 
236
238
  /**
237
239
  * @param {import('../types/options.d.ts').ResolvedOptions} options
240
+ * @param {import('vite').ResolvedConfig} viteConfig
238
241
  */
239
- function enforceOptionsForHmr(options) {
242
+ function enforceOptionsForHmr(options, viteConfig) {
243
+ if (options.hot && viteConfig.server.hmr === false) {
244
+ log.warn(
245
+ 'vite config server.hmr is false but hot is true. Forcing hot to false as it would not work.'
246
+ );
247
+ options.hot = false;
248
+ }
240
249
  if (isSvelte5) {
241
250
  if (options.hot && isSvelte5WithHMRSupport) {
242
251
  log.warn(