rollup-plugin-purgecss 7.0.2 → 9.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/lib/rollup-plugin-purgecss.d.ts +31 -4
- package/lib/rollup-plugin-purgecss.esm.js +5 -9
- package/lib/rollup-plugin-purgecss.js +6 -10
- package/package.json +22 -11
- package/__tests__/assets/actual_a.css +0 -8
- package/__tests__/assets/expect_a.css +0 -8
- package/__tests__/assets/test_a.css +0 -12
- package/__tests__/assets/test_a.html +0 -8
- package/__tests__/fixtures/basic/index.js +0 -5
- package/__tests__/index.test.ts +0 -27
- package/build.ts +0 -25
- package/jest.config.ts +0 -2
- package/src/index.ts +0 -80
- package/src/types/index.ts +0 -26
- package/tsconfig.json +0 -14
|
@@ -26,8 +26,29 @@ declare type ComplexSafelist = {
|
|
|
26
26
|
* in the final CSS, even if `child-of-bg` is not found.
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
|
-
deep?:
|
|
30
|
-
|
|
29
|
+
deep?: StringRegExpArray;
|
|
30
|
+
/**
|
|
31
|
+
* You can safelist whole selectors if any part of that selector matches a
|
|
32
|
+
* pattern with `safelist.greedy`
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const purgecss = await new PurgeCSS().purge({
|
|
38
|
+
* content: [],
|
|
39
|
+
* css: [],
|
|
40
|
+
* safelist: {
|
|
41
|
+
* greedy: [/red$/]
|
|
42
|
+
* }
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* In this example, selectors such as `button.bg-red.nonexistent-class`
|
|
47
|
+
* will be left in the final CSS, even if `button` and `nonexistent-class`
|
|
48
|
+
* are not found.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
greedy?: StringRegExpArray;
|
|
31
52
|
variables?: StringRegExpArray;
|
|
32
53
|
keyframes?: StringRegExpArray;
|
|
33
54
|
};
|
|
@@ -96,6 +117,12 @@ declare interface RawCSS {
|
|
|
96
117
|
}
|
|
97
118
|
|
|
98
119
|
/**
|
|
120
|
+
* Strings and regular expressions an option is matched against. A string
|
|
121
|
+
* matches a value exactly, except a string written between slashes, like
|
|
122
|
+
* `"/^btn-/"` or `"/^btn-/i"`, which is parsed as a regular expression. This
|
|
123
|
+
* form lets configuration files that cannot contain regular expressions, such
|
|
124
|
+
* as `postcss.config.json`, use patterns.
|
|
125
|
+
*
|
|
99
126
|
* @public
|
|
100
127
|
*/
|
|
101
128
|
declare type StringRegExpArray = Array<RegExp | string>;
|
|
@@ -107,7 +134,7 @@ declare type StringRegExpArray = Array<RegExp | string>;
|
|
|
107
134
|
*/
|
|
108
135
|
export declare type UserDefinedOptions = Omit<UserDefinedOptions_2, "css" | "output" | "rejectedCss"> & {
|
|
109
136
|
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
|
|
110
|
-
output
|
|
137
|
+
output?: UserDefinedOptions_2["output"] | OutputFunction | boolean;
|
|
111
138
|
insert?: boolean;
|
|
112
139
|
include?: string | RegExp | (string | RegExp)[];
|
|
113
140
|
exclude?: string | RegExp | (string | RegExp)[];
|
|
@@ -153,7 +180,7 @@ declare interface UserDefinedOptions_2 {
|
|
|
153
180
|
/** {@inheritDoc purgecss#Options.skippedContentGlobs} */
|
|
154
181
|
skippedContentGlobs?: Array<string>;
|
|
155
182
|
/** {@inheritDoc purgecss#Options.dynamicAttributes} */
|
|
156
|
-
dynamicAttributes?:
|
|
183
|
+
dynamicAttributes?: StringRegExpArray;
|
|
157
184
|
}
|
|
158
185
|
|
|
159
186
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { PurgeCSS } from 'purgecss';
|
|
3
|
-
import { createFilter } from 'rollup
|
|
3
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -19,7 +19,9 @@ function pluginPurgeCSS(options) {
|
|
|
19
19
|
if (!filter(id))
|
|
20
20
|
return null;
|
|
21
21
|
const v = await new PurgeCSS().purge({
|
|
22
|
-
|
|
22
|
+
...options,
|
|
23
|
+
// `output` is an option of the plugin, not of PurgeCSS
|
|
24
|
+
output: undefined,
|
|
23
25
|
css: [
|
|
24
26
|
{
|
|
25
27
|
raw: code,
|
|
@@ -54,13 +56,7 @@ function pluginPurgeCSS(options) {
|
|
|
54
56
|
if (typeof options.output === "function") {
|
|
55
57
|
return options.output(css, styles);
|
|
56
58
|
}
|
|
57
|
-
if (!options.insert && dest)
|
|
58
|
-
if (dest.endsWith(".js") || dest.endsWith(".ts")) {
|
|
59
|
-
dest = dest.slice(0, -3);
|
|
60
|
-
}
|
|
61
|
-
dest = `${dest}.css`;
|
|
62
|
-
return fs.writeFileSync(dest, css);
|
|
63
|
-
}
|
|
59
|
+
if (!options.insert && dest) ;
|
|
64
60
|
},
|
|
65
61
|
};
|
|
66
62
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var purgecss = require('purgecss');
|
|
5
|
-
var
|
|
5
|
+
var pluginutils = require('@rollup/pluginutils');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -31,7 +31,7 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
|
31
31
|
* @public
|
|
32
32
|
*/
|
|
33
33
|
function pluginPurgeCSS(options) {
|
|
34
|
-
const filter =
|
|
34
|
+
const filter = pluginutils.createFilter(options.include || ["**/*.css"], options.exclude || "node_modules/**");
|
|
35
35
|
const styles = [];
|
|
36
36
|
let dest = "";
|
|
37
37
|
return {
|
|
@@ -40,7 +40,9 @@ function pluginPurgeCSS(options) {
|
|
|
40
40
|
if (!filter(id))
|
|
41
41
|
return null;
|
|
42
42
|
const v = await new purgecss.PurgeCSS().purge({
|
|
43
|
-
|
|
43
|
+
...options,
|
|
44
|
+
// `output` is an option of the plugin, not of PurgeCSS
|
|
45
|
+
output: undefined,
|
|
44
46
|
css: [
|
|
45
47
|
{
|
|
46
48
|
raw: code,
|
|
@@ -75,13 +77,7 @@ function pluginPurgeCSS(options) {
|
|
|
75
77
|
if (typeof options.output === "function") {
|
|
76
78
|
return options.output(css, styles);
|
|
77
79
|
}
|
|
78
|
-
if (!options.insert && dest)
|
|
79
|
-
if (dest.endsWith(".js") || dest.endsWith(".ts")) {
|
|
80
|
-
dest = dest.slice(0, -3);
|
|
81
|
-
}
|
|
82
|
-
dest = `${dest}.css`;
|
|
83
|
-
return fs__namespace.writeFileSync(dest, css);
|
|
84
|
-
}
|
|
80
|
+
if (!options.insert && dest) ;
|
|
85
81
|
},
|
|
86
82
|
};
|
|
87
83
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-purgecss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Rollup plugin for purgecss",
|
|
5
5
|
"main": "lib/rollup-plugin-purgecss.js",
|
|
6
|
-
"module": "./lib/rollup-plugin-purgecss.
|
|
7
|
-
"jsnext:main": "./lib/rollup-plugin-purgecss.
|
|
6
|
+
"module": "./lib/rollup-plugin-purgecss.esm.js",
|
|
7
|
+
"jsnext:main": "./lib/rollup-plugin-purgecss.esm.js",
|
|
8
8
|
"directories": {
|
|
9
9
|
"lib": "lib",
|
|
10
10
|
"test": "__tests__"
|
|
11
11
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
16
15
|
"repository": {
|
|
17
16
|
"type": "git",
|
|
18
17
|
"url": "git+https://github.com/FullHuman/purgecss.git"
|
|
@@ -26,17 +25,29 @@
|
|
|
26
25
|
],
|
|
27
26
|
"author": "Ffloriel",
|
|
28
27
|
"license": "MIT",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.12.0"
|
|
30
|
+
},
|
|
29
31
|
"bugs": {
|
|
30
32
|
"url": "https://github.com/FullHuman/purgecss/issues"
|
|
31
33
|
},
|
|
32
34
|
"homepage": "https://purgecss.com",
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
+
"@rollup/pluginutils": "^5.4.0",
|
|
37
|
+
"purgecss": "^9.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"rollup": "^4.66.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"rollup": "^3.0.0 || ^4.0.0"
|
|
36
44
|
},
|
|
37
45
|
"publishConfig": {
|
|
38
46
|
"access": "public",
|
|
39
47
|
"registry": "https://registry.npmjs.org/"
|
|
40
48
|
},
|
|
41
|
-
"
|
|
42
|
-
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "ts-node build.ts",
|
|
51
|
+
"test": "jest"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/__tests__/index.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { rollup } from "rollup";
|
|
4
|
-
import purgecss from "./../src/";
|
|
5
|
-
|
|
6
|
-
describe("rollup-plugin-purgecss", () => {
|
|
7
|
-
it("remove unused css", async () => {
|
|
8
|
-
const bundle = await rollup({
|
|
9
|
-
input: path.resolve(__dirname, "fixtures/basic/index.js"),
|
|
10
|
-
plugins: [
|
|
11
|
-
purgecss({
|
|
12
|
-
content: [path.resolve(__dirname, "assets/test_a.html")],
|
|
13
|
-
output: path.resolve(__dirname, "assets/actual_a.css"),
|
|
14
|
-
}),
|
|
15
|
-
],
|
|
16
|
-
});
|
|
17
|
-
await bundle.generate({ format: "cjs", exports: "auto" });
|
|
18
|
-
|
|
19
|
-
const actualA = fs
|
|
20
|
-
.readFileSync(path.resolve(__dirname, "assets/actual_a.css"))
|
|
21
|
-
.toString();
|
|
22
|
-
const expectA = fs
|
|
23
|
-
.readFileSync(path.resolve(__dirname, "assets/expect_a.css"))
|
|
24
|
-
.toString();
|
|
25
|
-
expect(actualA).toEqual(expectA);
|
|
26
|
-
});
|
|
27
|
-
});
|
package/build.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildRollup,
|
|
3
|
-
createRollupConfig,
|
|
4
|
-
extractAPI,
|
|
5
|
-
} from "../../scripts/build";
|
|
6
|
-
import { promises as asyncFs } from "fs";
|
|
7
|
-
import * as path from "path";
|
|
8
|
-
|
|
9
|
-
(async () => {
|
|
10
|
-
await asyncFs.rm(path.resolve(__dirname, "lib"), {
|
|
11
|
-
recursive: true,
|
|
12
|
-
force: true,
|
|
13
|
-
});
|
|
14
|
-
const rollupConfig = createRollupConfig("rollup-plugin-purgecss", [
|
|
15
|
-
"fs",
|
|
16
|
-
"rollup-pluginutils",
|
|
17
|
-
"purgecss",
|
|
18
|
-
]);
|
|
19
|
-
await buildRollup(rollupConfig);
|
|
20
|
-
await extractAPI(__dirname);
|
|
21
|
-
await asyncFs.rm(path.resolve(__dirname, "lib", ".temp"), {
|
|
22
|
-
recursive: true,
|
|
23
|
-
force: true,
|
|
24
|
-
});
|
|
25
|
-
})();
|
package/jest.config.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { PurgeCSS } from "purgecss";
|
|
3
|
-
import { Plugin } from "rollup";
|
|
4
|
-
import { createFilter } from "rollup-pluginutils";
|
|
5
|
-
import { UserDefinedOptions } from "./types";
|
|
6
|
-
|
|
7
|
-
export * from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param options - options
|
|
12
|
-
* @returns
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
function pluginPurgeCSS(options: UserDefinedOptions): Plugin {
|
|
17
|
-
const filter = createFilter(
|
|
18
|
-
options.include || ["**/*.css"],
|
|
19
|
-
options.exclude || "node_modules/**",
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const styles: string[] = [];
|
|
23
|
-
let dest = "";
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
name: "purgecss",
|
|
27
|
-
transform: async (code, id) => {
|
|
28
|
-
if (!filter(id)) return null;
|
|
29
|
-
|
|
30
|
-
const v = await new PurgeCSS().purge({
|
|
31
|
-
content: options.content,
|
|
32
|
-
css: [
|
|
33
|
-
{
|
|
34
|
-
raw: code,
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
});
|
|
38
|
-
let css = v[0].css;
|
|
39
|
-
|
|
40
|
-
styles.push(css);
|
|
41
|
-
|
|
42
|
-
css = JSON.stringify(css);
|
|
43
|
-
if (options.insert) {
|
|
44
|
-
// do thing
|
|
45
|
-
} else if (!options.output) {
|
|
46
|
-
code = css;
|
|
47
|
-
} else {
|
|
48
|
-
code = `"";`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
code: `export default ${code}`,
|
|
53
|
-
map: { mappings: "" },
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
generateBundle() {
|
|
57
|
-
if (!options.insert && (!styles.length || options.output === false)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const css = styles.reduce((acc, value) => {
|
|
61
|
-
return acc + value;
|
|
62
|
-
}, "");
|
|
63
|
-
if (typeof options.output === "string") {
|
|
64
|
-
return fs.writeFileSync(options.output, css);
|
|
65
|
-
}
|
|
66
|
-
if (typeof options.output === "function") {
|
|
67
|
-
return options.output(css, styles);
|
|
68
|
-
}
|
|
69
|
-
if (!options.insert && dest) {
|
|
70
|
-
if (dest.endsWith(".js") || dest.endsWith(".ts")) {
|
|
71
|
-
dest = dest.slice(0, -3);
|
|
72
|
-
}
|
|
73
|
-
dest = `${dest}.css`;
|
|
74
|
-
return fs.writeFileSync(dest, css);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default pluginPurgeCSS;
|
package/src/types/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RawContent,
|
|
3
|
-
UserDefinedOptions as PurgeCSSUserDefinedOptions,
|
|
4
|
-
} from "purgecss";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export type OutputFunction = (css: string, styles: string[]) => void;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* {@inheritDoc purgecss#UserDefinedOptions}
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export type UserDefinedOptions = Omit<
|
|
17
|
-
PurgeCSSUserDefinedOptions,
|
|
18
|
-
"css" | "output" | "rejectedCss"
|
|
19
|
-
> & {
|
|
20
|
-
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
|
|
21
|
-
output: PurgeCSSUserDefinedOptions["output"] | OutputFunction | boolean;
|
|
22
|
-
insert?: boolean;
|
|
23
|
-
include?: string | RegExp | (string | RegExp)[];
|
|
24
|
-
exclude?: string | RegExp | (string | RegExp)[];
|
|
25
|
-
dest?: string;
|
|
26
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"outDir": "./lib",
|
|
6
|
-
"declarationDir": "./.temp/",
|
|
7
|
-
"baseUrl": ".",
|
|
8
|
-
"paths": {
|
|
9
|
-
"purgecss": ["../purgecss/src"],
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"include": ["./src/**/*", "./../purgecss/src/*"],
|
|
13
|
-
"exclude": ["./lib"]
|
|
14
|
-
}
|