Skip to content

Commit

Permalink
feat!: vite 6 support (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Nov 21, 2024
1 parent e262266 commit e3344b4
Show file tree
Hide file tree
Showing 38 changed files with 413 additions and 402 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-lions-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': minor
---

Add `esm-env` to `ssr.noExternal` by default to resolve its conditions with Vite
5 changes: 5 additions & 0 deletions .changeset/light-phones-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': major
---

Handle Vite 6 breaking change and remove Vite 5 handling
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"svelte-eslint-parser": "^0.43.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.15.0",
"vite": "^5.4.11",
"vite": "^6.0.0-beta.10",
"vitest": "^2.1.5"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/autoprefixer-browerslist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postcss-load-config": "^6.0.1",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/configfile-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/configfile-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/css-dev-sourcemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"sass": "^1.81.0",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/custom-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/dynamic-compile-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/hmr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"e2e-test-dep-vite-plugins": "file:../_test_dependencies/vite-plugins",
"node-fetch": "^3.3.2",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/import-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"sass": "^1.81.0",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/inspector-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@sveltejs/kit": "^2.8.1",
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/inspector-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
8 changes: 5 additions & 3 deletions packages/e2e-tests/kit-node/__tests__/kit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import glob from 'tiny-glob';
import path from 'node:path';
import { defaultClientConditions, defaultClientMainFields } from 'vite';
import { describe, expect, it } from 'vitest';

describe('kit-node', () => {
Expand Down Expand Up @@ -285,7 +286,8 @@ describe('kit-node', () => {
'/^svelte\\//', // serialized with toString
'e2e-test-dep-svelte-api-only',
'svelte-i18n',
'esm-env',
'esm-env', // first added by svelte-kit
'esm-env', // second added by vite-plugin-svelte
'@sveltejs/kit'
],
`ssr.noExternal in ${filename}`
Expand Down Expand Up @@ -346,12 +348,12 @@ describe('kit-node', () => {
expectArrayEqual(config.resolve.dedupe, expectedDedupe, `resolve.dedupe in ${filename}`);
expectArrayEqual(
config.resolve.mainFields,
['svelte', 'browser', 'module', 'jsnext:main', 'jsnext'],
['svelte', ...defaultClientMainFields],
`resolve.mainFields in ${filename}`
);
expectArrayEqual(
config.resolve.conditions,
['svelte'],
[...defaultClientConditions, 'svelte'],
`resolve.conditions in ${filename}`
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/kit-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"svelte-i18n": "^4.0.1",
"tiny-glob": "^0.2.9",
"typescript": "^5.6.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/package-json-svelte-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"sass": "^1.81.0",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
6 changes: 3 additions & 3 deletions packages/e2e-tests/prebundle-svelte-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"e2e-test-dep-svelte-api-only": "file:../_test_dependencies/svelte-api-only",
"e2e-test-dep-svelte-exports-simple": "file:../_test_dependencies/svelte-exports-simple",
"e2e-test-dep-svelte-hybrid": "file:../_test_dependencies/svelte-hybrid",
"e2e-test-dep-svelte-module": "file:../_test_dependencies/svelte-module",
"e2e-test-dep-svelte-nested": "file:../_test_dependencies/svelte-nested",
"e2e-test-dep-svelte-simple": "file:../_test_dependencies/svelte-simple",
"e2e-test-dep-svelte-module": "file:../_test_dependencies/svelte-module"
"e2e-test-dep-svelte-simple": "file:../_test_dependencies/svelte-simple"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"sass": "^1.81.0",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/preprocess-with-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sass": "^1.81.0",
"stylus": "^0.64.0",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/resolve-exports-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/scan-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/svelte-preprocess/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"typescript": "^5.6.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/ts-type-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@types/node": "^22.9.1",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"npm-run-all2": "^7.0.1",
"serve-static": "^1.16.2",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/playground/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"e2e-test-dep-svelte-module": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/playground/big-component-library-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"svelte-check": "^4.0.9",
"svelte-preprocess": "^6.0.3",
"typescript": "^5.6.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"lodash-es": "^4.17.21",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/playground/big-component-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"carbon-preprocess-svelte": "^0.11.7",
"svelte": "^5.2.4",
"svelte-preprocess": "^6.0.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"dependencies": {
"lodash-es": "^4.17.21"
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/big/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/playground/kit-demo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"svelte": "^5.2.4",
"svelte-check": "^4.0.9",
"typescript": "^5.6.3",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/playground/optimizedeps-include/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@sveltejs/vite-plugin-svelte": "workspace:^",
"svelte": "^5.2.4",
"tinro": "^0.6.12",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte-inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"devDependencies": {
"@types/debug": "^4.1.12",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
"esbuild": "^0.24.0",
"sass": "^1.81.0",
"svelte": "^5.2.4",
"vite": "^5.4.11"
"vite": "^6.0.0-beta.10"
}
}
14 changes: 13 additions & 1 deletion packages/vite-plugin-svelte/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
validateInlineOptions,
resolveOptions,
patchResolvedViteConfig,
preResolveOptions
preResolveOptions,
ensureConfigEnvironmentMainFields,
ensureConfigEnvironmentConditions
} from './utils/options.js';
import { ensureWatchedFile, setupWatchers } from './utils/watch.js';
import { toRollupError } from './utils/error.js';
Expand Down Expand Up @@ -64,6 +66,16 @@ export function svelte(inlineOptions) {
return extraViteConfig;
},

configEnvironment(name, config, opts) {
ensureConfigEnvironmentMainFields(name, config, opts);
// @ts-expect-error the function above should make `resolve.mainFields` non-nullable
config.resolve.mainFields.unshift('svelte');

ensureConfigEnvironmentConditions(name, config, opts);
// @ts-expect-error the function above should make `resolve.conditions` non-nullable
config.resolve.conditions.push('svelte');
},

async configResolved(config) {
options = resolveOptions(options, config, cache);
patchResolvedViteConfig(config, options);
Expand Down
4 changes: 0 additions & 4 deletions packages/vite-plugin-svelte/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { createRequire } from 'node:module';

export const VITE_RESOLVE_MAIN_FIELDS = ['browser', 'module', 'jsnext:main', 'jsnext'];

export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];

export const SVELTE_IMPORTS = Object.entries(
createRequire(import.meta.url)('svelte/package.json').exports
)
Expand Down
Loading

0 comments on commit e3344b4

Please sign in to comment.