@sveltejs/vite-plugin-svelte 1.0.0-next.39 → 1.0.0-next.40

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": "1.0.0-next.39",
3
+ "version": "1.0.0-next.40",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
42
42
  "dependencies": {
43
- "@rollup/pluginutils": "^4.1.2",
43
+ "@rollup/pluginutils": "^4.2.0",
44
44
  "debug": "^4.3.3",
45
45
  "kleur": "^4.1.4",
46
- "magic-string": "^0.25.7",
47
- "svelte-hmr": "^0.14.9"
46
+ "magic-string": "^0.26.1",
47
+ "svelte-hmr": "^0.14.11"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "diff-match-patch": "^1.0.5",
@@ -60,11 +60,11 @@
60
60
  "@types/debug": "^4.1.7",
61
61
  "@types/diff-match-patch": "^1.0.32",
62
62
  "diff-match-patch": "^1.0.5",
63
- "esbuild": "^0.14.23",
64
- "rollup": "^2.68.0",
63
+ "esbuild": "^0.14.26",
64
+ "rollup": "^2.70.1",
65
65
  "svelte": "^3.46.4",
66
- "tsup": "^5.11.13",
67
- "vite": "^2.8.4"
66
+ "tsup": "^5.12.1",
67
+ "vite": "^2.8.6"
68
68
  },
69
69
  "scripts": {
70
70
  "dev": "pnpm run build:ci -- --sourcemap --watch src",
package/src/index.ts CHANGED
@@ -55,7 +55,7 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
55
55
  // @ts-expect-error temporarily lend the options variable until fixed in configResolved
56
56
  options = await preResolveOptions(inlineOptions, config, configEnv);
57
57
  // extra vite config
58
- const extraViteConfig = buildExtraViteConfig(options, config, configEnv);
58
+ const extraViteConfig = buildExtraViteConfig(options, config);
59
59
  log.debug('additional vite config', extraViteConfig);
60
60
  return extraViteConfig;
61
61
  },
@@ -184,8 +184,7 @@ function resolveViteRoot(viteConfig: UserConfig): string | undefined {
184
184
 
185
185
  export function buildExtraViteConfig(
186
186
  options: PreResolvedOptions,
187
- config: UserConfig,
188
- configEnv: ConfigEnv
187
+ config: UserConfig
189
188
  ): Partial<UserConfig> {
190
189
  // extra handling for svelte dependencies in the project
191
190
  const svelteDeps = findRootSvelteDependencies(options.root);
@@ -200,7 +199,7 @@ export function buildExtraViteConfig(
200
199
  // knownJsSrcExtensions: options.extensions
201
200
  };
202
201
 
203
- if (configEnv.command === 'serve') {
202
+ if (options.isServe) {
204
203
  extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
205
204
  svelteDeps,
206
205
  options,
@@ -209,7 +208,7 @@ export function buildExtraViteConfig(
209
208
  }
210
209
 
211
210
  // @ts-ignore
212
- extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config);
211
+ extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
213
212
 
214
213
  return extraViteConfig;
215
214
  }
@@ -294,7 +293,7 @@ function buildSSROptionsForSvelte(
294
293
  // add svelte to ssr.noExternal unless it is present in ssr.external
295
294
  // so we can resolve it with svelte/ssr
296
295
  if (options.isBuild && config.build?.ssr) {
297
- // @ts-ignore
296
+ // @ts-expect-error ssr still flagged in vite
298
297
  if (!config.ssr?.external?.includes('svelte')) {
299
298
  noExternal.push('svelte');
300
299
  }
@@ -309,13 +308,30 @@ function buildSSROptionsForSvelte(
309
308
  // add svelte dependencies to ssr.noExternal unless present in ssr.external or optimizeDeps.include
310
309
  noExternal.push(
311
310
  ...Array.from(new Set(svelteDeps.map((s) => s.name))).filter((x) => {
312
- // @ts-ignore
311
+ // @ts-expect-error ssr still flagged in vite
313
312
  return !config.ssr?.external?.includes(x) && !config.optimizeDeps?.include?.includes(x);
314
313
  })
315
314
  );
316
- return {
315
+ const ssr = {
317
316
  noExternal
318
317
  };
318
+
319
+ if (options.isServe) {
320
+ // during dev, we have to externalize transitive dependencies, see https://github.com/sveltejs/vite-plugin-svelte/issues/281
321
+ // @ts-expect-error ssr still flagged in vite
322
+ ssr.external = Array.from(
323
+ new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
324
+ ).filter(
325
+ (dep) =>
326
+ !ssr.noExternal.includes(dep) &&
327
+ // @ts-expect-error ssr still flagged in vite
328
+ !config.ssr?.noExternal?.includes(dep) &&
329
+ // @ts-expect-error ssr still flagged in vite
330
+ !config.ssr?.external?.includes(dep)
331
+ );
332
+ }
333
+
334
+ return ssr;
319
335
  }
320
336
 
321
337
  export function patchResolvedViteConfig(viteConfig: ResolvedConfig, options: ResolvedOptions) {