add compact property when the user run pnpm run build

This commit is contained in:
wuls 2023-03-31 09:49:27 +08:00
parent c440edf07f
commit c85a4b0e60
3 changed files with 24 additions and 0 deletions

View file

@ -426,6 +426,23 @@ export interface AstroUserConfig {
*/
site?: string;
/**
* @docs
* @name compact
* @type {boolean}
* @default `true`
* @description
* Set to `true` to enable compact mode. This will remove all whitespace from your final HTMl file, including newlines. This is useful for reducing the size of your final build html bundle
*
* ```js
* {
* compact: true
* }
* ```
*/
compact?: boolean;
/**
* @docs
* @name base

View file

@ -37,6 +37,7 @@ export async function compile({
// use `sourcemap: "both"` so that sourcemap is included in the code
// result passed to esbuild, but also available in the catch handler.
transformResult = await transform(source, {
compact: astroConfig.compact,
filename,
normalizedFilename: normalizeFilename(filename, astroConfig.root),
sourcemap: 'both',

View file

@ -22,6 +22,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
assets: '_astro',
serverEntry: 'entry.mjs',
},
compact: true,
server: {
host: false,
port: 3000,
@ -62,6 +63,7 @@ export const AstroConfigSchema = z.object({
.default(ASTRO_CONFIG_DEFAULTS.outDir)
.transform((val) => new URL(val)),
site: z.string().url().optional(),
compact: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compact),
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base),
trailingSlash: z
.union([z.literal('always'), z.literal('never'), z.literal('ignore')])
@ -197,6 +199,10 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
.string()
.default(ASTRO_CONFIG_DEFAULTS.srcDir)
.transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
compact: z
.boolean()
.optional()
.default(ASTRO_CONFIG_DEFAULTS.compact),
publicDir: z
.string()
.default(ASTRO_CONFIG_DEFAULTS.publicDir)