diff --git a/.changeset/tricky-eagles-enjoy.md b/.changeset/tricky-eagles-enjoy.md new file mode 100644 index 000000000..4285d2c19 --- /dev/null +++ b/.changeset/tricky-eagles-enjoy.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes use of --experimental-static-build with markdown pages diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index c424ec92d..1caeebdb1 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -1,4 +1,4 @@ -import type { OutputChunk, PreRenderedChunk, RollupOutput } from 'rollup'; +import type { OutputChunk, OutputAsset, PreRenderedChunk, RollupOutput } from 'rollup'; import type { Plugin as VitePlugin, UserConfig } from '../vite'; import type { AstroConfig, RouteCache, SSRElement } from '../../@types/astro'; import type { AllPagesData } from './types'; @@ -35,6 +35,17 @@ function addPageName(pathname: string, opts: StaticBuildOptions): void { opts.pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, '')); } +// Determines of a Rollup chunk is an entrypoint page. +function chunkIsPage(output: OutputAsset | OutputChunk, internals: BuildInternals) { + if(output.type !== 'chunk') { + return false; + } + const chunk = output as OutputChunk; + return chunk.facadeModuleId && + (internals.entrySpecifierToBundleMap.has(chunk.facadeModuleId) || + internals.entrySpecifierToBundleMap.has('/' + chunk.facadeModuleId)); +} + export async function staticBuild(opts: StaticBuildOptions) { const { allPages, astroConfig } = opts; @@ -158,8 +169,8 @@ async function generatePages(result: RollupOutput, opts: StaticBuildOptions, int debug(opts.logging, 'generate', 'End build step, now generating'); const generationPromises = []; for (let output of result.output) { - if (output.type === 'chunk' && output.facadeModuleId && output.facadeModuleId.endsWith('.astro')) { - generationPromises.push(generatePage(output, opts, internals, facadeIdToPageDataMap)); + if (chunkIsPage(output, internals)) { + generationPromises.push(generatePage(output as OutputChunk, opts, internals, facadeIdToPageDataMap)); } } await Promise.all(generationPromises); diff --git a/packages/astro/test/fixtures/static-build/src/layouts/Main.astro b/packages/astro/test/fixtures/static-build/src/layouts/Main.astro new file mode 100644 index 000000000..b6af3a4fe --- /dev/null +++ b/packages/astro/test/fixtures/static-build/src/layouts/Main.astro @@ -0,0 +1,6 @@ + + +Testing + + + diff --git a/packages/astro/test/fixtures/static-build/src/pages/index.astro b/packages/astro/test/fixtures/static-build/src/pages/index.astro new file mode 100644 index 000000000..e22975e58 --- /dev/null +++ b/packages/astro/test/fixtures/static-build/src/pages/index.astro @@ -0,0 +1,6 @@ + + +Testing + +

Testing

+ diff --git a/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md b/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md new file mode 100644 index 000000000..76e108103 --- /dev/null +++ b/packages/astro/test/fixtures/static-build/src/pages/posts/thoughts.md @@ -0,0 +1,7 @@ +--- +layout: ../../layouts/Main.astro +--- + +# Post + +Testing here diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js new file mode 100644 index 000000000..2e0896cce --- /dev/null +++ b/packages/astro/test/static-build.test.js @@ -0,0 +1,28 @@ +import { expect } from 'chai'; +import cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; + +describe('Static build', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + projectRoot: './fixtures/static-build/', + renderers: [], + buildOptions: { + experimentalStaticBuild: true, + }, + }); + await fixture.build(); + }); + + it('Builds out .astro pags', async () => { + const html = await fixture.readFile('/index.html'); + expect(html).to.be.a('string'); + }); + + it('Builds out .md pages', async () => { + const html = await fixture.readFile('/posts/thoughts/index.html'); + expect(html).to.be.a('string'); + }); +});