Skip to content

Commit

Permalink
0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed May 11, 2022
1 parent e63c5e6 commit 6fb6029
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## 0.0.5

- Bug fix

## 0.0.4

- Bug fix
- Bug fix

## 0.0.3

- Updates README.md
- Updates README.md
- Refactor

## 0.0.2
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
This **[Astro integration][astro-integration]** brings compression utilities to
your Astro project.

[csso](https://npmjs.org/csso)
[html-minifier-terser](https://npmjs.org/html-minifier-terser)
[terser](https://npmjs.org/html-minifier-terser)
[csso] [html-minifier-terser] [terser]

## Installation

Expand Down Expand Up @@ -57,8 +55,8 @@ export default defineConfig({

## Getting started

The utility should now automatically compress all your CSS, HTML and JavaScript files in the
dist folder.
The utility should now automatically compress all your CSS, HTML and JavaScript
files in the dist folder.

You can override any of the default options from the configurations of:

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default interface Options {
/**
* [csso] options.
*/
css?: CSS;
css?: CSS | false;
/**
* [html-minifier-terser] options.
*/
html?: HTML;
html?: HTML | false;
/**
* [terser] options.
*/
js?: JS;
js?: JS | false;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro-compress",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"description": "AstroJS compression utilities. Compress HTML, CSS, JavaScript and more.",
"repository": {
Expand Down
47 changes: 32 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Options from "./options";
// @ts-ignore
import * as cssoMinify from "csso";
// @ts-ignore
import htmlMinifierTerserMinify from "html-minifier-terser";
import * as htmlMinifierTerserMinify from "html-minifier-terser";
import { minify as terserMinify } from "terser";

import CSS from "./options/csso";
Expand Down Expand Up @@ -35,23 +35,32 @@ const minify = async (

case "html-minifier-terser":
await fs.promises.readFile(file, "utf-8").then(async (data) => {
await fs.promises.writeFile(
file,
htmlMinifierTerserMinify.minify(data, options),
"utf-8"
);
await htmlMinifierTerserMinify
.minify(data, options)
.then(async (minified: string) => {
await fs.promises.writeFile(
file,
minified,
"utf-8"
);
});
});

break;

case "terser":
await fs.promises.writeFile(
file,
await fs.promises.readFile(file, "utf-8").then(async (data) => {
// @ts-ignore
await terserMinify(file, options).code,
"utf-8"
);

await terserMinify(data, options).then(
async (minified: any) => {
await fs.promises.writeFile(
file,
minified.code,
"utf-8"
);
}
);
});
break;

default:
Expand Down Expand Up @@ -136,19 +145,27 @@ export default function createPlugin(
hooks: {
"astro:build:done": async () => {
if (options.css) {
minify(`${options.path}**/*.css`, options.css, "csso");
await minify(
`${options.path}**/*.css`,
options.css,
"csso"
);
}

if (options.html) {
minify(
await minify(
`${options.path}**/*.html`,
options.html,
"html-minifier-terser"
);
}

if (options.js) {
minify(`${options.path}**/*.js`, options.js, "terser");
await minify(
`${options.path}**/*.js`,
options.js,
"terser"
);
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export default interface Options {
/**
* [csso] options.
*/
css?: CSS;
css?: CSS | false;

/**
* [html-minifier-terser] options.
*/
html?: HTML;
html?: HTML | false;

/**
* [terser] options.
*/
js?: JS;
js?: JS | false;
}

0 comments on commit 6fb6029

Please sign in to comment.