@zubyjs/purgecss 1.0.57

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.
Files changed (4) hide show
  1. package/README.md +59 -0
  2. package/index.d.ts +12 -0
  3. package/index.js +38 -0
  4. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @zubyjs/purgecss
2
+
3
+ The plugin for Zuby.js that will analyze your application
4
+ using [PurgeCSS](https://purgecss.com) and remove unused CSS to keep your application as small as possible.
5
+
6
+ ## Installation
7
+
8
+ First, install the `@zubyjs/purgecss` package using your favorite package manager.
9
+ If you aren't sure, you can use npm:
10
+
11
+ ```sh
12
+ npm install @zubyjs/purgecss
13
+ ```
14
+
15
+ Then add the `@zubyjs/purgecss` plugin to your `zuby.config.mjs` file under the `plugins` option:
16
+
17
+ ```diff lang="js" title="zuby.config.mjs"
18
+ import { defineConfig } from 'zuby';
19
+ import preact from '@zubyjs/preact';
20
+ + import purgecss from '@zubyjs/purgecss';
21
+
22
+ export default defineConfig({
23
+ outDir: '.zuby',
24
+ jsx: preact(),
25
+ + plugins: [
26
+ + purgecss()
27
+ + ]
28
+ ^^^^^^^^
29
+ });
30
+ ```
31
+
32
+ And that's it! You are ready to use all the power of PurgeCSS in your application.
33
+
34
+ NOTE: Always make sure that all zuby packages are in sync in your `package.json` file:
35
+
36
+ ```diff lang="json"
37
+ {
38
+ "name": "my-zuby-app",
39
+ "version": "1.0.0",
40
+ "dependencies": {
41
+ "zuby": "latest",
42
+ "@zubyjs/purgecss": "latest"
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ This package is part of Zuby.js workspace and maintained by the team behind the [Zuby package](https://www.npmjs.com/package/zuby).
50
+ Please refer to it for more details how to contribute.
51
+
52
+ ## Acknowledgements
53
+
54
+ This plugin is port of [astro-purgecss](https://github.com/codiume/orbit/tree/main/packages/astro-purgecss) package
55
+ for Zuby.js Plugin API.
56
+
57
+ ## License
58
+
59
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { UserDefinedOptions } from 'purgecss';
2
+ import { ZubyPlugin } from 'zuby/index.js';
3
+ export interface PurgeCssPluginOptions extends Partial<UserDefinedOptions> {
4
+ }
5
+ /**
6
+ * Zuby.js plugin that integrates Tailwind CSS
7
+ * with your application.
8
+ * @param options
9
+ * @returns ZubyPlugin
10
+ */
11
+ declare const _default: (options?: PurgeCssPluginOptions) => ZubyPlugin;
12
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ // This is port of the:
2
+ // https://github.com/codiume/orbit/tree/main/packages/astro-purgecss
3
+ // for the Zuby.js Plugin API
4
+ import { PurgeCSS } from 'purgecss';
5
+ import { writeFile } from 'fs/promises';
6
+ import { normalizePath } from 'zuby/utils/pathUtils.js';
7
+ /**
8
+ * Zuby.js plugin that integrates Tailwind CSS
9
+ * with your application.
10
+ * @param options
11
+ * @returns ZubyPlugin
12
+ */
13
+ export default (options = {}) => ({
14
+ name: 'zuby-purgecss-plugin',
15
+ description: 'purging unused CSS...',
16
+ buildStep: true,
17
+ hooks: {
18
+ 'zuby:build:done': async ({ config, logger }) => {
19
+ const { outDir } = config;
20
+ const purgeCss = new PurgeCSS();
21
+ logger.info(`Analyzing '${outDir}' dir for unused CSS...`);
22
+ const purged = await purgeCss.purge({
23
+ css: [normalizePath(`${outDir}/**/*.css`)],
24
+ defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
25
+ ...options,
26
+ content: [
27
+ normalizePath(`${outDir}/**/*.html`),
28
+ normalizePath(`${outDir}/**/*.js`),
29
+ ...(options.content || []),
30
+ ],
31
+ });
32
+ purged.forEach(({ file }) => logger.info(`Purged: ${file}`));
33
+ await Promise.all(purged
34
+ .filter(({ file }) => file?.endsWith('.css'))
35
+ .map(async ({ css, file }) => await writeFile(file, css)));
36
+ },
37
+ },
38
+ });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@zubyjs/purgecss",
3
+ "version": "1.0.57",
4
+ "description": "Zuby.js purgecss plugin",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "release": "cd ./dist && npm publish --access public && cd ..",
9
+ "bump-version": "npm version patch",
10
+ "build": "rm -rf dist/ stage/ && mkdir dist && tsc && cp -rf package.json README.md stage/purgecss/src/* dist/ && rm -rf stage/",
11
+ "push-build": "npm run build && cd dist && yalc push --force && cd ..",
12
+ "test": "exit 0"
13
+ },
14
+ "publishConfig": {
15
+ "directory": "dist",
16
+ "linkDirectory": true
17
+ },
18
+ "peerDependencies": {
19
+ "zuby": "^1.0.0"
20
+ },
21
+ "dependencies": {
22
+ "purgecss": "^5.0.0"
23
+ },
24
+ "bugs": {
25
+ "url": "https://gitlab.com/futrou/zuby.js/-/issues",
26
+ "email": "zuby@futrou.com"
27
+ },
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://gitlab.com/futrou/zuby.js.git"
32
+ },
33
+ "homepage": "https://zubyjs.com",
34
+ "keywords": [
35
+ "zuby-plugin",
36
+ "zuby",
37
+ "tailwind",
38
+ "css"
39
+ ],
40
+ "engines": {
41
+ "node": ">=18"
42
+ }
43
+ }