Skip to content

Commit

Permalink
Allow specifying entryFileNames for client JS (#3676)
Browse files Browse the repository at this point in the history
* Allow specifying entryFileNames for client JS

* Adds a changeset
  • Loading branch information
matthewp authored Jun 22, 2022
1 parent c97bdf1 commit 85c3375
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/spotty-rockets-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Allow specifying entryFileNames for client JS
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions packages/astro/test/entry-file-names.test.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions packages/astro/test/fixtures/entry-file-names/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions packages/astro/test/fixtures/entry-file-names/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/entry-file-names",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/preact": "workspace:",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export default function() {
return (
<div id="hello">Hello world</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
import Hello from '../components/Hello.jsx';
---

<html>
<head><title>Test</title></head>
<body>
<Hello client:load />
</body>
</html>
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 85c3375

Please sign in to comment.