Allow overriding build vite config options (#3392)
* Allow overriding build vite config options * Adds a changeset * Test svelte * Move plugins down * Assign after for the client too * Spread output options on manually * Remove .only
This commit is contained in:
parent
54aba7231d
commit
2939be5f2d
7 changed files with 61 additions and 1 deletions
5
.changeset/eleven-gifts-matter.md
Normal file
5
.changeset/eleven-gifts-matter.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Allows vite config to override options used in the build
|
|
@ -944,6 +944,7 @@ export interface AstroIntegration {
|
||||||
vite: ViteConfigWithSSR;
|
vite: ViteConfigWithSSR;
|
||||||
pages: Map<string, PageBuildData>;
|
pages: Map<string, PageBuildData>;
|
||||||
target: 'client' | 'server';
|
target: 'client' | 'server';
|
||||||
|
updateConfig: (newConfig: ViteConfigWithSSR) => void;
|
||||||
}) => void | Promise<void>;
|
}) => void | Promise<void>;
|
||||||
'astro:build:done'?: (options: {
|
'astro:build:done'?: (options: {
|
||||||
pages: { pathname: string }[];
|
pages: { pathname: string }[];
|
||||||
|
|
|
@ -142,6 +142,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
entryFileNames: opts.buildConfig.serverEntry,
|
entryFileNames: opts.buildConfig.serverEntry,
|
||||||
chunkFileNames: 'chunks/chunk.[hash].mjs',
|
chunkFileNames: 'chunks/chunk.[hash].mjs',
|
||||||
assetFileNames: 'assets/asset.[hash][extname]',
|
assetFileNames: 'assets/asset.[hash][extname]',
|
||||||
|
...viteConfig.build?.rollupOptions?.output
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ssr: true,
|
ssr: true,
|
||||||
|
@ -222,6 +223,7 @@ async function clientBuild(
|
||||||
entryFileNames: 'entry.[hash].js',
|
entryFileNames: 'entry.[hash].js',
|
||||||
chunkFileNames: 'chunks/chunk.[hash].js',
|
chunkFileNames: 'chunks/chunk.[hash].js',
|
||||||
assetFileNames: 'assets/asset.[hash][extname]',
|
assetFileNames: 'assets/asset.[hash][extname]',
|
||||||
|
...viteConfig.build?.rollupOptions?.output
|
||||||
},
|
},
|
||||||
preserveEntrySignatures: 'exports-only',
|
preserveEntrySignatures: 'exports-only',
|
||||||
},
|
},
|
||||||
|
|
|
@ -134,7 +134,14 @@ export async function runHookBuildSetup({
|
||||||
}) {
|
}) {
|
||||||
for (const integration of config.integrations) {
|
for (const integration of config.integrations) {
|
||||||
if (integration.hooks['astro:build:setup']) {
|
if (integration.hooks['astro:build:setup']) {
|
||||||
await integration.hooks['astro:build:setup']({ vite, pages, target });
|
await integration.hooks['astro:build:setup']({
|
||||||
|
vite,
|
||||||
|
pages,
|
||||||
|
target,
|
||||||
|
updateConfig: (newConfig) => {
|
||||||
|
mergeConfig(vite, newConfig);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
packages/astro/test/config-vite.test.js
Normal file
18
packages/astro/test/config-vite.test.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import * as cheerio from 'cheerio';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
|
||||||
|
describe('Vite Config', async () => {
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({ root: './fixtures/config-vite/' });
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Allows overriding bundle naming options in the build', async () => {
|
||||||
|
const html = await fixture.readFile('/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('link').attr('href')).to.equal('/assets/testing-entry.css');
|
||||||
|
});
|
||||||
|
});
|
14
packages/astro/test/fixtures/config-vite/astro.config.mjs
vendored
Normal file
14
packages/astro/test/fixtures/config-vite/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
vite: {
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
chunkFileNames: 'assets/testing-[name].js',
|
||||||
|
assetFileNames: 'assets/testing-[name].[ext]'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
13
packages/astro/test/fixtures/config-vite/src/pages/index.astro
vendored
Normal file
13
packages/astro/test/fixtures/config-vite/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testing</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: aquamarine;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue