Allow specifying entryFileNames for client JS (#3676)

* Allow specifying entryFileNames for client JS

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-06-22 12:32:17 -04:00 committed by GitHub
parent c97bdf1a45
commit 85c33751c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Allow specifying entryFileNames for client JS

View file

@ -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,

View 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);
})
});

View 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`,
},
},
},
},
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/entry-file-names",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/preact": "workspace:",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,6 @@
export default function() {
return (
<div id="hello">Hello world</div>
)
}

View file

@ -0,0 +1,10 @@
---
import Hello from '../components/Hello.jsx';
---
<html>
<head><title>Test</title></head>
<body>
<Hello client:load />
</body>
</html>

View file

@ -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