add minification for pro

This commit is contained in:
wuls 2023-04-18 18:37:38 +08:00
parent cbc2b2fd55
commit 644dae1ee9
5 changed files with 12 additions and 12 deletions

View file

@ -441,19 +441,19 @@ export interface AstroUserConfig {
/**
* @docs
* @name compact
* @name compressHTML
* @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
* Set to `true` to enable compressHTML 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
* compressHTML: true
* }
* ```
*/
compact?: boolean;
compressHTML?: boolean;
/**
* @docs

View file

@ -37,7 +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,
compact: astroConfig.compressHTML,
filename,
normalizedFilename: normalizeFilename(filename, astroConfig.root),
sourcemap: 'both',

View file

@ -22,7 +22,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
assets: '_astro',
serverEntry: 'entry.mjs',
},
compact: true,
compressHTML: false,
server: {
host: false,
port: 3000,
@ -63,7 +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),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base),
trailingSlash: z
.union([z.literal('always'), z.literal('never'), z.literal('ignore')])
@ -200,10 +200,10 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
.string()
.default(ASTRO_CONFIG_DEFAULTS.srcDir)
.transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
compact: z
compressHTML: z
.boolean()
.optional()
.default(ASTRO_CONFIG_DEFAULTS.compact),
.default(ASTRO_CONFIG_DEFAULTS.compressHTML),
publicDir: z
.string()
.default(ASTRO_CONFIG_DEFAULTS.publicDir)

View file

@ -4,7 +4,7 @@ import { loadFixture, isWindows } from './test-utils.js';
describe('minification html', () => {
let fixture;
const regex = /[ \n]/;
const regex = /[\r\n]+/gm;
before(async () => {
fixture = await loadFixture({ root: './fixtures/minification-html/' });
await fixture.build();
@ -17,7 +17,7 @@ describe('minification html', () => {
it('validating the html is or not is minification ', async () => {
const html = await fixture.readFile('/index.html');
expect(regex.test(html)).to.equal(false);
expect(regex.test(html.slice(20))).to.equal(false);
});
});

View file

@ -2,5 +2,5 @@ import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({
compact: true
compressHTML: true
});