astro-purgecss 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # 🚀 Astro Purgecss
2
+
3
+ [![version][version-badge]][npm]
4
+ [![downloads][downloads-badge]][npm]
5
+ [![github actions][github-actions-badge]][github-actions]
6
+ [![typescript][typescript-badge]][typescript]
7
+ [![makepr][makepr-badge]][makepr]
8
+
9
+ [Purgecss][purgecss] helps you remove unused CSS rules from your final astro bundle.
10
+
11
+ ## 📦 Installation
12
+
13
+ ### Quick Install
14
+
15
+ the `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren’t sure which package manager you’re using, run the first command.) Then, follow the prompts, and type “y” in the terminal (meaning “yes”) for each one.
16
+
17
+ ```bash
18
+ # Using NPM
19
+ npx astro add astro-purgecss
20
+ # Using Yarn
21
+ yarn astro add astro-purgecss
22
+ # Using PNPM
23
+ pnpm astro add astro-purgecss
24
+ ```
25
+
26
+ ### Manual Install
27
+
28
+ First, install the `astro-purgecss` package using your package manager. (If you aren’t sure which package manager you’re using, run the first command.)
29
+
30
+ ```bash
31
+ # Using NPM
32
+ npm install astro-purgecss
33
+ # Using Yarn
34
+ yarn add astro-purgecss
35
+ # Using PNPM
36
+ pnpm install astro-purgecss
37
+ ```
38
+
39
+ Then, apply this integration to your `astro.config.mjs` file using the integrations property:
40
+
41
+ ```js
42
+ import purgecss from 'astro-purgecss';
43
+
44
+ export default {
45
+ // ...
46
+ integrations: [purgecss()]
47
+ };
48
+ ```
49
+
50
+ > **Note**
51
+ >
52
+ > To make sure this integration works properly, it's recommended to put `purgecss()`
53
+ > as the last element in the `integrations` array.
54
+
55
+ ## 🥑 Usage
56
+
57
+ When you install this integration, things will be auto-wired for you. and all your generated css files should be purged from unused classes automagically.
58
+
59
+ ## What does this integration do, exactly?
60
+
61
+ This integration hooks into your astro build cycle, more precisely `astro:build:done`, it reads all your generated `HTML` and `CSS` files, and analyzes them using [Purgecss][purgecss] to remove any unsued CSS rules.
62
+
63
+ ## Change log
64
+
65
+ Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.
66
+
67
+ ## Acknowledgements
68
+
69
+ - [Purgecss][purgecss]
70
+
71
+ [npm]: https://npmjs.com/package/astro-purgecss
72
+ [purgecss]: https://purgecss.com
73
+
74
+ <!-- Readme Badges -->
75
+
76
+ [version-badge]: https://img.shields.io/npm/v/astro-purgecss.svg
77
+ [downloads-badge]: https://img.shields.io/npm/dt/astro-purgecss
78
+ [github-actions]: https://github.com/codiume/orbit/actions
79
+ [github-actions-badge]: https://github.com/codiume/orbit/actions/workflows/node.js.yml/badge.svg
80
+ [typescript]: https://www.typescriptlang.org/dt/search?search=astro-purgecss
81
+ [typescript-badge]: https://img.shields.io/npm/types/astro-purgecss
82
+ [makepr]: https://makeapullrequest.com
83
+ [makepr-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square?style=flat
@@ -0,0 +1,2 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ export default function (): AstroIntegration;
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ import { PurgeCSS } from "purgecss";
2
+ import { writeFile } from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ function src_default() {
5
+ return {
6
+ name: "astro-purgecss",
7
+ hooks: {
8
+ "astro:build:done": async ({ dir }) => {
9
+ const outDir = fileURLToPath(dir);
10
+ const purged = await new PurgeCSS().purge({
11
+ content: [`${outDir}/**/*.html`],
12
+ css: [`${outDir}/**/*.css`]
13
+ });
14
+ await Promise.all(
15
+ purged.filter(({ file }) => file.endsWith(".css")).map(async ({ css, file }) => await writeFile(file, css))
16
+ );
17
+ }
18
+ }
19
+ };
20
+ }
21
+ export {
22
+ src_default as default
23
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "astro-purgecss",
3
+ "description": "Remove unused CSS rules from your final Astro bundle",
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "build": "astro-build --src src/**/*.ts",
7
+ "postbuild": "npm run typecheck:emit",
8
+ "typecheck": "tsc --noEmit",
9
+ "typecheck:emit": "tsc --declaration --emitDeclarationOnly --outDir dist"
10
+ },
11
+ "type": "module",
12
+ "types": "dist/index.d.ts",
13
+ "author": "codiume",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/codiume/orbit.git",
18
+ "directory": "packages/astro-purgecss"
19
+ },
20
+ "keywords": [
21
+ "astro",
22
+ "astro-component",
23
+ "astro-integration",
24
+ "css",
25
+ "optimization"
26
+ ],
27
+ "bugs": "https://github.com/codiume/orbit/issues",
28
+ "homepage": "https://github.com/codiume/orbit",
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "main": "./dist/index.mjs",
33
+ "exports": {
34
+ ".": "./dist/index.mjs"
35
+ },
36
+ "peerDependencies": {
37
+ "astro": "^1.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "purgecss": "^4.1.3"
41
+ }
42
+ }