Respect Vite user config for third-party packages (#5345)

This commit is contained in:
Bjorn Lu 2022-11-11 14:22:43 +08:00 committed by GitHub
parent 7ec016fec3
commit 3ae2a961b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 16 deletions

View file

@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/solid-js': patch
---
Respect Vite user config for third-party packages config handling

View file

@ -158,7 +158,7 @@
"unist-util-visit": "^4.1.0",
"vfile": "^5.3.2",
"vite": "~3.2.1",
"vitefu": "^0.1.0",
"vitefu": "^0.2.0",
"yargs-parser": "^21.0.1",
"zod": "^3.17.3"
},

View file

@ -62,6 +62,7 @@ export async function createVite(
const astroPkgsConfig = await crawlFrameworkPkgs({
root: fileURLToPath(settings.config.root),
isBuild: mode === 'build',
viteUserConfig: settings.config.vite,
isFrameworkPkgByJson(pkgJson) {
return (
// Attempt: package relies on `astro`. ✅ Definitely an Astro package

View file

@ -33,7 +33,7 @@
},
"dependencies": {
"babel-preset-solid": "^1.4.2",
"vitefu": "^0.1.0"
"vitefu": "^0.2.0"
},
"devDependencies": {
"astro": "workspace:*",

View file

@ -1,10 +1,12 @@
import type { AstroConfig } from 'astro';
import { fileURLToPath } from 'url';
import { crawlFrameworkPkgs } from 'vitefu';
export async function getSolidPkgsConfig(root: URL, isBuild: boolean) {
export async function getSolidPkgsConfig(isBuild: boolean, astroConfig: AstroConfig) {
return await crawlFrameworkPkgs({
root: fileURLToPath(root),
root: fileURLToPath(astroConfig.root),
isBuild,
viteUserConfig: astroConfig.vite,
isFrameworkPkgByJson(pkgJson) {
return containsSolidField(pkgJson.exports || {});
},

View file

@ -1,4 +1,4 @@
import type { AstroIntegration, AstroRenderer } from 'astro';
import type { AstroConfig, AstroIntegration, AstroRenderer } from 'astro';
import { getSolidPkgsConfig } from './dependencies.js';
function getRenderer(): AstroRenderer {
@ -24,11 +24,11 @@ function getRenderer(): AstroRenderer {
};
}
async function getViteConfiguration(isDev: boolean, root: URL) {
async function getViteConfiguration(isDev: boolean, astroConfig: AstroConfig) {
// https://github.com/solidjs/vite-plugin-solid
// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];
const solidPkgsConfig = await getSolidPkgsConfig(root, !isDev);
const solidPkgsConfig = await getSolidPkgsConfig(!isDev, astroConfig);
return {
/**
* We only need esbuild on .ts or .js files.
@ -58,7 +58,7 @@ export default function (): AstroIntegration {
hooks: {
'astro:config:setup': async ({ command, addRenderer, updateConfig, config }) => {
addRenderer(getRenderer());
updateConfig({ vite: await getViteConfiguration(command === 'dev', config.root) });
updateConfig({ vite: await getViteConfiguration(command === 'dev', config) });
},
},
};

View file

@ -465,7 +465,7 @@ importers:
unist-util-visit: ^4.1.0
vfile: ^5.3.2
vite: ~3.2.1
vitefu: ^0.1.0
vitefu: ^0.2.0
yargs-parser: ^21.0.1
zod: ^3.17.3
dependencies:
@ -527,7 +527,7 @@ importers:
unist-util-visit: 4.1.1
vfile: 5.3.5
vite: 3.2.3_sass@1.56.1
vitefu: 0.1.1_vite@3.2.3
vitefu: 0.2.0_vite@3.2.3
yargs-parser: 21.1.1
zod: 3.19.1
devDependencies:
@ -3115,10 +3115,10 @@ importers:
astro-scripts: workspace:*
babel-preset-solid: ^1.4.2
solid-js: ^1.5.1
vitefu: ^0.1.0
vitefu: ^0.2.0
dependencies:
babel-preset-solid: 1.6.1
vitefu: 0.1.1
vitefu: 0.2.0
devDependencies:
astro: link:../../astro
astro-scripts: link:../../../scripts
@ -18131,8 +18131,8 @@ packages:
fsevents: 2.3.2
dev: false
/vitefu/0.1.1:
resolution: {integrity: sha512-HClD14fjMJ+NQgXBqT3dC3RdO/+Chayil+cCPYZKY3kT+KcJomKzrdgzfCHJkIL2L0OAY+VPvrSW615iPtc7ag==}
/vitefu/0.2.0:
resolution: {integrity: sha512-58946QxFCr0OnNbF73JPA3nyzfI65G82bWwKV8zxAcQfTeAyGU99ejSFIG7RBUDBUr1RonXI/VEMzIrNl/euXA==}
peerDependencies:
vite: ^3.0.0
peerDependenciesMeta:
@ -18140,8 +18140,8 @@ packages:
optional: true
dev: false
/vitefu/0.1.1_vite@3.2.3:
resolution: {integrity: sha512-HClD14fjMJ+NQgXBqT3dC3RdO/+Chayil+cCPYZKY3kT+KcJomKzrdgzfCHJkIL2L0OAY+VPvrSW615iPtc7ag==}
/vitefu/0.2.0_vite@3.2.3:
resolution: {integrity: sha512-58946QxFCr0OnNbF73JPA3nyzfI65G82bWwKV8zxAcQfTeAyGU99ejSFIG7RBUDBUr1RonXI/VEMzIrNl/euXA==}
peerDependencies:
vite: ^3.0.0
peerDependenciesMeta: