-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to Vite 4 #5685
Upgrade to Vite 4 #5685
Changes from all commits
0afab4b
5bc5e1b
37d46cf
5619157
9d0ceb9
24531ed
f6e9a1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'astro': major | ||
'@astrojs/svelte': major | ||
'@astrojs/vue': major | ||
--- | ||
|
||
Upgrade to Vite 4. Please see its [migration guide](https://vitejs.dev/guide/migration.html) for more information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/svelte': major | ||
--- | ||
|
||
Simplify Svelte preprocess setup. `<style lang="postcss">` is now required if using PostCSS inside style tags. |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { collectErrorMetadata } from './utils.js'; | ||
export { createCustomViteLogger, enhanceViteSSRError, getViteErrorPayload } from './vite.js'; | ||
export { enhanceViteSSRError, getViteErrorPayload } from './vite.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<style> | ||
<style lang="postcss"> | ||
.svelte { | ||
&.nested { | ||
color: red; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,6 @@ | |
"chai": "^4.3.6", | ||
"cheerio": "^1.0.0-rc.11", | ||
"mocha": "^9.2.2", | ||
"vite": "^3.0.0" | ||
"vite": "^4.0.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import type { Options } from '@sveltejs/vite-plugin-svelte'; | ||
import { svelte } from '@sveltejs/vite-plugin-svelte'; | ||
import type { AstroConfig, AstroIntegration, AstroRenderer } from 'astro'; | ||
import preprocess from 'svelte-preprocess'; | ||
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte'; | ||
import type { AstroIntegration, AstroRenderer } from 'astro'; | ||
import type { UserConfig } from 'vite'; | ||
|
||
function getRenderer(): AstroRenderer { | ||
|
@@ -15,27 +14,13 @@ function getRenderer(): AstroRenderer { | |
type ViteConfigurationArgs = { | ||
isDev: boolean; | ||
options?: Options | OptionsCallback; | ||
postcssConfig: AstroConfig['style']['postcss']; | ||
}; | ||
|
||
function getViteConfiguration({ | ||
options, | ||
postcssConfig, | ||
isDev, | ||
}: ViteConfigurationArgs): UserConfig { | ||
function getViteConfiguration({ options, isDev }: ViteConfigurationArgs): UserConfig { | ||
const defaultOptions: Partial<Options> = { | ||
emitCss: true, | ||
compilerOptions: { dev: isDev, hydratable: true }, | ||
preprocess: [ | ||
preprocess({ | ||
less: true, | ||
postcss: postcssConfig, | ||
sass: { renderSync: true }, | ||
scss: { renderSync: true }, | ||
stylus: true, | ||
typescript: true, | ||
}), | ||
], | ||
preprocess: [vitePreprocess()], | ||
}; | ||
Comment on lines
-29
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This introduced a small breaking change where |
||
|
||
// Disable hot mode during the build | ||
|
@@ -65,7 +50,7 @@ function getViteConfiguration({ | |
|
||
return { | ||
optimizeDeps: { | ||
include: ['@astrojs/svelte/client.js', 'svelte', 'svelte/internal'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vite-plugin-svelte includes the removed identifiers by default. |
||
include: ['@astrojs/svelte/client.js'], | ||
exclude: ['@astrojs/svelte/server.js'], | ||
}, | ||
plugins: [svelte(resolvedOptions)], | ||
|
@@ -78,13 +63,12 @@ export default function (options?: Options | OptionsCallback): AstroIntegration | |
name: '@astrojs/svelte', | ||
hooks: { | ||
// Anything that gets returned here is merged into Astro Config | ||
'astro:config:setup': ({ command, updateConfig, addRenderer, config }) => { | ||
'astro:config:setup': ({ command, updateConfig, addRenderer }) => { | ||
addRenderer(getRenderer()); | ||
updateConfig({ | ||
vite: getViteConfiguration({ | ||
options, | ||
isDev: command === 'dev', | ||
postcssConfig: config.style.postcss, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removal is safe because internally Astro passes it down to Vite, which when we use |
||
}), | ||
}); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite 4 doesn't mutate
NODE_ENV
anymore, unless it'sundefined
. So if we run the dev server, and then build, build would run indevelopment
NODE_ENV
instead, which broke the MDX test.This shouldn't affect users in practice, but internally for our tests we need to make sure
NODE_ENV
is the right value we're testing.