Allow specifying entryFileNames for client JS (#3676)
* Allow specifying entryFileNames for client JS * Adds a changeset
This commit is contained in:
parent
c97bdf1a45
commit
85c33751c2
8 changed files with 81 additions and 1 deletions
5
.changeset/spotty-rockets-grow.md
Normal file
5
.changeset/spotty-rockets-grow.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Allow specifying entryFileNames for client JS
|
|
@ -116,10 +116,10 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
|||
input: [],
|
||||
output: {
|
||||
format: 'esm',
|
||||
entryFileNames: opts.buildConfig.serverEntry,
|
||||
chunkFileNames: 'chunks/[name].[hash].mjs',
|
||||
assetFileNames: 'assets/[name].[hash][extname]',
|
||||
...viteConfig.build?.rollupOptions?.output,
|
||||
entryFileNames: opts.buildConfig.serverEntry,
|
||||
},
|
||||
},
|
||||
ssr: true,
|
||||
|
|
26
packages/astro/test/entry-file-names.test.js
Normal file
26
packages/astro/test/entry-file-names.test.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('vite.build.rollupOptions.entryFileNames', () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/entry-file-names',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Renders correctly', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#hello')).to.have.a.lengthOf(1);
|
||||
});
|
||||
|
||||
it('Outputs a client module that was specified by the config', async () => {
|
||||
const js = await fixture.readFile('/assets/js/Hello.js');
|
||||
expect(js).to.be.a('string');
|
||||
expect(js.length).to.be.greaterThan(0);
|
||||
})
|
||||
});
|
16
packages/astro/test/fixtures/entry-file-names/astro.config.mjs
vendored
Normal file
16
packages/astro/test/fixtures/entry-file-names/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import preact from '@astrojs/preact';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [preact()],
|
||||
vite: {
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: `assets/js/[name].js`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
9
packages/astro/test/fixtures/entry-file-names/package.json
vendored
Normal file
9
packages/astro/test/fixtures/entry-file-names/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/entry-file-names",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/preact": "workspace:",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
6
packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx
vendored
Normal file
6
packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
export default function() {
|
||||
return (
|
||||
<div id="hello">Hello world</div>
|
||||
)
|
||||
}
|
10
packages/astro/test/fixtures/entry-file-names/src/pages/index.astro
vendored
Normal file
10
packages/astro/test/fixtures/entry-file-names/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
import Hello from '../components/Hello.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
<head><title>Test</title></head>
|
||||
<body>
|
||||
<Hello client:load />
|
||||
</body>
|
||||
</html>
|
|
@ -1370,6 +1370,14 @@ importers:
|
|||
dependencies:
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/entry-file-names:
|
||||
specifiers:
|
||||
'@astrojs/preact': 'workspace:'
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/preact': link:../../../../integrations/preact
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/error-react-spectrum:
|
||||
specifiers:
|
||||
'@adobe/react-spectrum': ^3.18.0
|
||||
|
|
Loading…
Reference in a new issue