From 8be8b9241ab5ff6ad269ef57dc3777dce4293735 Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Sun, 8 May 2022 17:33:22 +0300 Subject: [PATCH] 0.0.2 --- CHANGELOG.md | 4 ++++ dist/index.js | 4 ++-- dist/options.d.ts | 12 ++++++------ dist/options/csso.d.ts | 2 +- dist/options/html-minifier.d.ts | 2 +- package.json | 2 +- src/index.ts | 26 +++++++++++++++----------- src/options.ts | 12 ++++++------ src/options/csso.ts | 2 +- src/options/html-minifier.ts | 2 +- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d7b3de..e89c900f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.2 + +- Refactor + ## 0.0.1 - Initial version diff --git a/dist/index.js b/dist/index.js index d67eaf76..5d107391 100644 --- a/dist/index.js +++ b/dist/index.js @@ -62,8 +62,8 @@ function createPlugin(integrationOptions = {}) { hooks: { "astro:build:done": async ({ pages }) => { const files = { - css: FastGlob.sync(`${options.path}**/*.css`), - html: pages.map((page) => { + css: !options.css ? [] : FastGlob.sync(`${options.path}**/*.css`), + html: !options.html ? [] : pages.map((page) => { const pathname = page.pathname.endsWith("/") ? page.pathname : `${page.pathname}/`; const file = pathname === "404/" ? "404.html" : `${pathname}index.html`; return `${options.path}${file}`; diff --git a/dist/options.d.ts b/dist/options.d.ts index 79a6d7bd..ba33cf3d 100644 --- a/dist/options.d.ts +++ b/dist/options.d.ts @@ -1,5 +1,5 @@ -import { CSS } from "./options/csso"; -import { HTML } from "./options/html-minifier"; +import CSS from "./options/csso"; +import HTML from "./options/html-minifier"; export default interface Options { /** * Astro build path. @@ -7,11 +7,11 @@ export default interface Options { */ path?: string; /** - * csso options. + * [csso] options. */ - css?: CSS; + css?: CSS | false; /** - * html-minifier options. + * [html-minifier-terser] options. */ - html?: HTML; + html?: HTML | false; } diff --git a/dist/options/csso.d.ts b/dist/options/csso.d.ts index 734c0b17..86737417 100644 --- a/dist/options/csso.d.ts +++ b/dist/options/csso.d.ts @@ -6,7 +6,7 @@ export interface afterCompressOptions { compressResult?: String; options?: {}; } -export interface CSS { +export default interface CSS { /** * Generate a source map when true. * Default: false diff --git a/dist/options/html-minifier.d.ts b/dist/options/html-minifier.d.ts index 990e4108..b41bc25a 100644 --- a/dist/options/html-minifier.d.ts +++ b/dist/options/html-minifier.d.ts @@ -1,4 +1,4 @@ -export interface HTML { +export default interface HTML { /** * Treat attributes in case sensitive manner (useful for custom HTML tags). * Default: false diff --git a/package.json b/package.json index fe67e650..71b66e95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "astro-compress", - "version": "0.0.1", + "version": "0.0.2", "type": "module", "description": "AstroJS compression utilities. Compress HTML, CSS, JavaScript and more.", "repository": { diff --git a/src/index.ts b/src/index.ts index b87fec90..b6dff8ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,19 +77,23 @@ export default function createPlugin( hooks: { "astro:build:done": async ({ pages }) => { const files: Files = { - css: FastGlob.sync(`${options.path}**/*.css`), - html: pages.map((page) => { - const pathname = page.pathname.endsWith("/") - ? page.pathname - : `${page.pathname}/`; + css: !options.css + ? [] + : FastGlob.sync(`${options.path}**/*.css`), + html: !options.html + ? [] + : pages.map((page) => { + const pathname = page.pathname.endsWith("/") + ? page.pathname + : `${page.pathname}/`; - const file = - pathname === "404/" - ? "404.html" - : `${pathname}index.html`; + const file = + pathname === "404/" + ? "404.html" + : `${pathname}index.html`; - return `${options.path}${file}`; - }), + return `${options.path}${file}`; + }), }; for (const type in files) { diff --git a/src/options.ts b/src/options.ts index df0d1cb5..349e91bc 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,5 +1,5 @@ -import { CSS } from "./options/csso"; -import { HTML } from "./options/html-minifier"; +import CSS from "./options/csso"; +import HTML from "./options/html-minifier"; export default interface Options { /** @@ -9,12 +9,12 @@ export default interface Options { path?: string; /** - * csso options. + * [csso] options. */ - css?: CSS; + css?: CSS | false; /** - * html-minifier options. + * [html-minifier-terser] options. */ - html?: HTML; + html?: HTML | false; } diff --git a/src/options/csso.ts b/src/options/csso.ts index 35722dc9..7133ae1c 100644 --- a/src/options/csso.ts +++ b/src/options/csso.ts @@ -8,7 +8,7 @@ export interface afterCompressOptions { options?: {}; } -export interface CSS { +export default interface CSS { /** * Generate a source map when true. * Default: false diff --git a/src/options/html-minifier.ts b/src/options/html-minifier.ts index 270e7c82..ae8bf8c0 100644 --- a/src/options/html-minifier.ts +++ b/src/options/html-minifier.ts @@ -1,4 +1,4 @@ -export interface HTML { +export default interface HTML { /** * Treat attributes in case sensitive manner (useful for custom HTML tags). * Default: false