astro-purgecss 1.0.0 → 1.1.1

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 CHANGED
@@ -56,13 +56,50 @@ export default {
56
56
 
57
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
58
 
59
- ## What does this integration do, exactly?
59
+ ## 📖 Configuration
60
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.
61
+ [PurgeCSS][purgecss] has a list of options that allow you to customize its behavior. And this Astro integration allow you to pass those options easily in your `astro.config.mjs` file:
62
62
 
63
- ## Change log
63
+ ```js
64
+ export default defineConfig({
65
+ integrations: [
66
+ purgecss({
67
+ fontFace: true,
68
+ keyframes: true,
69
+ safelist: ['random', 'yep', 'button', /^nav-/],
70
+ blocklist: ['usedClass', /^nav-/]
71
+ })
72
+ ]
73
+ });
74
+ ```
75
+
76
+ ### Available Options
77
+
78
+ Here is a list of options, that are allowed to be passed in the config:
79
+
80
+ ```ts
81
+ export type PurgeCSSOptions = {
82
+ fontFace?: boolean; // removes any unused @font-face if set to true
83
+ keyframes?: boolean; // removes unused keyframes by setting if set to true
84
+ rejected?: boolean; // scan through the removed list to see if there's anything wrong
85
+ rejectedCss?: boolean; // keeps the discarded CSS
86
+ variables?: boolean; // removes any unused CSS variables if set to true
87
+ safelist?: UserDefinedSafelist; // indicates which selectors are safe to leave in the final CSS
88
+ blocklist?: StringRegExpArray; // blocks the CSS selectors from appearing in the final output CSS
89
+ };
90
+ ```
91
+
92
+ To learn more about the available options, please refer to [PurgeCSS][purgecss-options] official docs.
93
+
94
+ ### Caveats
95
+
96
+ - Certain options (ex: `css`, `content`), are not allowed to be passed in your `astro.config.mjs` config file, to not interfere with the internals of this integration.
97
+
98
+ - If you are using `tailwind.css`, please read about purge limitations in this guide [writing-purgeable-html](https://v2.tailwindcss.com/docs/optimizing-for-production#writing-purgeable-html)
99
+
100
+ ## Changelog
64
101
 
65
- Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.
102
+ Please see the [Changelog](CHANGELOG.md) for more information on what has changed recently.
66
103
 
67
104
  ## Acknowledgements
68
105
 
@@ -70,6 +107,7 @@ Please see the [changelog](CHANGELOG.md) for more information on what has change
70
107
 
71
108
  [npm]: https://npmjs.com/package/astro-purgecss
72
109
  [purgecss]: https://purgecss.com
110
+ [purgecss-options]: https://purgecss.com/configuration.html#options
73
111
 
74
112
  <!-- Readme Badges -->
75
113
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,12 @@
1
1
  import type { AstroIntegration } from 'astro';
2
- export default function (): AstroIntegration;
2
+ import { StringRegExpArray, UserDefinedSafelist } from 'purgecss';
3
+ export declare type PurgeCSSOptions = {
4
+ fontFace?: boolean;
5
+ keyframes?: boolean;
6
+ rejected?: boolean;
7
+ rejectedCss?: boolean;
8
+ variables?: boolean;
9
+ safelist?: UserDefinedSafelist;
10
+ blocklist?: StringRegExpArray;
11
+ };
12
+ export default function (options?: PurgeCSSOptions): AstroIntegration;
package/dist/index.mjs CHANGED
@@ -1,15 +1,17 @@
1
1
  import { PurgeCSS } from "purgecss";
2
2
  import { writeFile } from "node:fs/promises";
3
3
  import { fileURLToPath } from "node:url";
4
- function src_default() {
4
+ function src_default(options = {}) {
5
5
  return {
6
6
  name: "astro-purgecss",
7
7
  hooks: {
8
8
  "astro:build:done": async ({ dir }) => {
9
9
  const outDir = fileURLToPath(dir);
10
10
  const purged = await new PurgeCSS().purge({
11
+ ...options,
11
12
  content: [`${outDir}/**/*.html`],
12
- css: [`${outDir}/**/*.css`]
13
+ css: [`${outDir}/**/*.css`],
14
+ defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || []
13
15
  });
14
16
  await Promise.all(
15
17
  purged.filter(({ file }) => file.endsWith(".css")).map(async ({ css, file }) => await writeFile(file, css))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "astro-purgecss",
3
3
  "description": "Remove unused CSS rules from your final Astro bundle",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "scripts": {
6
6
  "build": "astro-build --src src/**/*.ts",
7
7
  "postbuild": "npm run typecheck:emit",
@@ -33,10 +33,10 @@
33
33
  "exports": {
34
34
  ".": "./dist/index.mjs"
35
35
  },
36
+ "dependencies": {
37
+ "purgecss": "^4.1.3"
38
+ },
36
39
  "peerDependencies": {
37
40
  "astro": "^1.0.0"
38
- },
39
- "devDependencies": {
40
- "purgecss": "^4.1.3"
41
41
  }
42
42
  }