summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/silly-chairs-pretend.md5
-rw-r--r--packages/astro/src/core/build/index.ts53
-rw-r--r--packages/astro/src/core/build/page-data.ts6
-rw-r--r--packages/astro/src/core/errors.ts9
4 files changed, 26 insertions, 47 deletions
diff --git a/.changeset/silly-chairs-pretend.md b/.changeset/silly-chairs-pretend.md
new file mode 100644
index 000000000..0b0175cc7
--- /dev/null
+++ b/.changeset/silly-chairs-pretend.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Remove dev server during build
diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts
index 782f6652e..154a77a7a 100644
--- a/packages/astro/src/core/build/index.ts
+++ b/packages/astro/src/core/build/index.ts
@@ -5,7 +5,6 @@ import type { LogOptions } from '../logger/core';
import fs from 'fs';
import * as colors from 'kleur/colors';
import { performance } from 'perf_hooks';
-import * as vite from 'vite';
import {
runHookBuildDone,
runHookBuildStart,
@@ -18,7 +17,6 @@ import { debug, info, levels, timerMessage } from '../logger/core.js';
import { apply as applyPolyfill } from '../polyfill.js';
import { RouteCache } from '../render/route-cache.js';
import { createRouteManifest } from '../routing/index.js';
-import { createSafeError } from '../util.js';
import { collectPagesData } from './page-data.js';
import { staticBuild } from './static-build.js';
import { getTimeStat } from './util.js';
@@ -64,7 +62,6 @@ class AstroBuilder {
debug('build', 'Initial setup...');
const { logging } = this;
this.timer.init = performance.now();
- this.timer.viteStart = performance.now();
this.config = await runHookConfigSetup({ config: this.config, command: 'build' });
this.manifest = createRouteManifest({ config: this.config }, this.logging);
@@ -80,20 +77,11 @@ class AstroBuilder {
{ astroConfig: this.config, logging, mode: 'build' }
);
await runHookConfigDone({ config: this.config });
- const viteServer = await vite.createServer(viteConfig);
- debug('build', timerMessage('Vite started', this.timer.viteStart));
- return { viteConfig, viteServer };
+ return { viteConfig };
}
/** Run the build logic. build() is marked private because usage should go through ".run()" */
- private async build({
- viteConfig,
- viteServer,
- }: {
- viteConfig: ViteConfigWithSSR;
- viteServer: vite.ViteDevServer;
- }) {
- const { origin } = this;
+ private async build({ viteConfig }: { viteConfig: ViteConfigWithSSR }) {
const buildConfig: BuildConfig = {
client: new URL('./client/', this.config.outDir),
server: new URL('./server/', this.config.outDir),
@@ -111,10 +99,6 @@ class AstroBuilder {
astroConfig: this.config,
logging: this.logging,
manifest: this.manifest,
- origin,
- routeCache: this.routeCache,
- viteServer,
- ssr: this.config.output === 'server',
});
debug('build', timerMessage('All pages loaded', this.timer.loadStart));
@@ -131,24 +115,18 @@ class AstroBuilder {
colors.dim(`Completed in ${getTimeStat(this.timer.init, performance.now())}.`)
);
- try {
- await staticBuild({
- allPages,
- astroConfig: this.config,
- logging: this.logging,
- manifest: this.manifest,
- mode: this.mode,
- origin: this.origin,
- pageNames,
- routeCache: this.routeCache,
- viteConfig,
- buildConfig,
- });
- } catch (err: unknown) {
- // If the build doesn't complete, still shutdown the Vite server so the process doesn't hang.
- await viteServer.close();
- throw err;
- }
+ await staticBuild({
+ allPages,
+ astroConfig: this.config,
+ logging: this.logging,
+ manifest: this.manifest,
+ mode: this.mode,
+ origin: this.origin,
+ pageNames,
+ routeCache: this.routeCache,
+ viteConfig,
+ buildConfig,
+ });
// Write any additionally generated assets to disk.
this.timer.assetsStart = performance.now();
@@ -162,7 +140,6 @@ class AstroBuilder {
debug('build', timerMessage('Additional assets copied', this.timer.assetsStart));
// You're done! Time to clean up.
- await viteServer.close();
await runHookBuildDone({
config: this.config,
buildConfig,
@@ -186,7 +163,7 @@ class AstroBuilder {
try {
await this.build(setupData);
} catch (_err) {
- throw fixViteErrorMessage(createSafeError(_err), setupData.viteServer);
+ throw fixViteErrorMessage(_err);
}
}
diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts
index 97c6a2915..5de8804c4 100644
--- a/packages/astro/src/core/build/page-data.ts
+++ b/packages/astro/src/core/build/page-data.ts
@@ -1,4 +1,3 @@
-import type { ViteDevServer } from 'vite';
import type { AstroConfig, ManifestData } from '../../@types/astro';
import type { LogOptions } from '../logger/core';
import { info } from '../logger/core.js';
@@ -6,16 +5,11 @@ import type { AllPagesData } from './types';
import * as colors from 'kleur/colors';
import { debug } from '../logger/core.js';
-import { RouteCache } from '../render/route-cache.js';
export interface CollectPagesDataOptions {
astroConfig: AstroConfig;
logging: LogOptions;
manifest: ManifestData;
- origin: string;
- routeCache: RouteCache;
- viteServer: ViteDevServer;
- ssr: boolean;
}
export interface CollectPagesDataResult {
diff --git a/packages/astro/src/core/errors.ts b/packages/astro/src/core/errors.ts
index 13eec5cb8..f7ddd1f9f 100644
--- a/packages/astro/src/core/errors.ts
+++ b/packages/astro/src/core/errors.ts
@@ -42,11 +42,14 @@ export function cleanErrorStack(stack: string) {
.join('\n');
}
-/** Update the error message to correct any vite-isms that we don't want to expose to the user. */
-export function fixViteErrorMessage(_err: unknown, server: ViteDevServer, filePath?: URL) {
+/**
+ * Update the error message to correct any vite-isms that we don't want to expose to the user.
+ * The `server` is required if the error may come from `server.ssrLoadModule()`.
+ */
+export function fixViteErrorMessage(_err: unknown, server?: ViteDevServer, filePath?: URL) {
const err = createSafeError(_err);
// Vite will give you better stacktraces, using sourcemaps.
- server.ssrFixStacktrace(err);
+ server?.ssrFixStacktrace(err);
// Fix: Astro.glob() compiles to import.meta.glob() by the time Vite sees it,
// so we need to update this error message in case it originally came from Astro.glob().
if (err.message === 'import.meta.glob() can only accept string literals.') {