Skip to content
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

Respect Vite user config for third-party packages #5345

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/metal-suns-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/solid-js': patch
---

Respect Vite user config for third-party packages config handling
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"babel-preset-solid": "^1.4.2",
"vitefu": "^0.1.0"
"vitefu": "^0.2.0"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
6 changes: 4 additions & 2 deletions packages/integrations/solid/src/dependencies.ts
Original file line number Diff line number Diff line change
@@ -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 || {});
},
Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/solid/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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) });
},
},
};
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.