summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-06-22 12:32:17 -0400
committerGravatar GitHub <noreply@github.com> 2022-06-22 12:32:17 -0400
commit85c33751c20002e29bd646325a6e39f83cbb1f4d (patch)
tree31319e547b726a8cbd1ba0c5d0d5ac88d800e1fd
parentc97bdf1a45416ab7075463247b6469ee07753a5b (diff)
downloadastro-85c33751c20002e29bd646325a6e39f83cbb1f4d.tar.gz
astro-85c33751c20002e29bd646325a6e39f83cbb1f4d.tar.zst
astro-85c33751c20002e29bd646325a6e39f83cbb1f4d.zip
Allow specifying entryFileNames for client JS (#3676)
* Allow specifying entryFileNames for client JS * Adds a changeset
-rw-r--r--.changeset/spotty-rockets-grow.md5
-rw-r--r--packages/astro/src/core/build/static-build.ts2
-rw-r--r--packages/astro/test/entry-file-names.test.js26
-rw-r--r--packages/astro/test/fixtures/entry-file-names/astro.config.mjs16
-rw-r--r--packages/astro/test/fixtures/entry-file-names/package.json9
-rw-r--r--packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx6
-rw-r--r--packages/astro/test/fixtures/entry-file-names/src/pages/index.astro10
-rw-r--r--pnpm-lock.yaml8
8 files changed, 81 insertions, 1 deletions
diff --git a/.changeset/spotty-rockets-grow.md b/.changeset/spotty-rockets-grow.md
new file mode 100644
index 000000000..68d455432
--- /dev/null
+++ b/.changeset/spotty-rockets-grow.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Allow specifying entryFileNames for client JS
diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts
index fd49f9945..25e0b04e4 100644
--- a/packages/astro/src/core/build/static-build.ts
+++ b/packages/astro/src/core/build/static-build.ts
@@ -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,
diff --git a/packages/astro/test/entry-file-names.test.js b/packages/astro/test/entry-file-names.test.js
new file mode 100644
index 000000000..e9d1117c9
--- /dev/null
+++ b/packages/astro/test/entry-file-names.test.js
@@ -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);
+ })
+});
diff --git a/packages/astro/test/fixtures/entry-file-names/astro.config.mjs b/packages/astro/test/fixtures/entry-file-names/astro.config.mjs
new file mode 100644
index 000000000..fbca4b567
--- /dev/null
+++ b/packages/astro/test/fixtures/entry-file-names/astro.config.mjs
@@ -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`,
+ },
+ },
+ },
+ },
+});
diff --git a/packages/astro/test/fixtures/entry-file-names/package.json b/packages/astro/test/fixtures/entry-file-names/package.json
new file mode 100644
index 000000000..760acaedb
--- /dev/null
+++ b/packages/astro/test/fixtures/entry-file-names/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/entry-file-names",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/preact": "workspace:",
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx b/packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx
new file mode 100644
index 000000000..833f20f8e
--- /dev/null
+++ b/packages/astro/test/fixtures/entry-file-names/src/components/Hello.jsx
@@ -0,0 +1,6 @@
+
+export default function() {
+ return (
+ <div id="hello">Hello world</div>
+ )
+}
diff --git a/packages/astro/test/fixtures/entry-file-names/src/pages/index.astro b/packages/astro/test/fixtures/entry-file-names/src/pages/index.astro
new file mode 100644
index 000000000..aac79cece
--- /dev/null
+++ b/packages/astro/test/fixtures/entry-file-names/src/pages/index.astro
@@ -0,0 +1,10 @@
+---
+import Hello from '../components/Hello.jsx';
+---
+
+<html>
+ <head><title>Test</title></head>
+ <body>
+ <Hello client:load />
+ </body>
+</html>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8cede77ae..7224fe7fc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -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