gulp-purgecss 6.0.0-alpha.0 → 7.0.1-alpha.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/gulp-purgecss.d.ts +0 -2
- package/lib/gulp-purgecss.esm.js +99 -1
- package/lib/gulp-purgecss.js +120 -1
- package/package.json +4 -4
package/lib/gulp-purgecss.d.ts
CHANGED
package/lib/gulp-purgecss.esm.js
CHANGED
|
@@ -1 +1,99 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import * as glob from 'glob';
|
|
2
|
+
import PluginError from 'plugin-error';
|
|
3
|
+
import { PurgeCSS } from 'purgecss';
|
|
4
|
+
import through from 'through2';
|
|
5
|
+
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
6
|
+
|
|
7
|
+
const PLUGIN_NAME = "gulp-purgecss";
|
|
8
|
+
function getFiles(contentArray, ignore) {
|
|
9
|
+
return contentArray.reduce((acc, content) => {
|
|
10
|
+
return [...acc, ...glob.sync(content, { ignore })];
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param options - options
|
|
16
|
+
* @returns
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
function gulpPurgeCSS(options) {
|
|
21
|
+
return through.obj(async function (file, _encoding, callback) {
|
|
22
|
+
// empty
|
|
23
|
+
if (file.isNull())
|
|
24
|
+
return callback(null, file);
|
|
25
|
+
// buffer
|
|
26
|
+
if (file.isBuffer()) {
|
|
27
|
+
try {
|
|
28
|
+
const optionsGulp = {
|
|
29
|
+
...options,
|
|
30
|
+
content: getFiles(options.content, options.skippedContentGlobs),
|
|
31
|
+
css: [
|
|
32
|
+
{
|
|
33
|
+
raw: file.contents.toString(),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
stdin: true,
|
|
37
|
+
sourceMap: !!file.sourceMap,
|
|
38
|
+
};
|
|
39
|
+
const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
|
|
40
|
+
const purge = purgedCSSResults[0];
|
|
41
|
+
const result = optionsGulp.rejected && purge.rejected
|
|
42
|
+
? purge.rejected.join(" {}\n") + " {}"
|
|
43
|
+
: purge.css;
|
|
44
|
+
file.contents = Buffer.from(result, "utf-8");
|
|
45
|
+
// apply source map to the chain
|
|
46
|
+
if (file.sourceMap) {
|
|
47
|
+
applySourceMap(file, purge.sourceMap);
|
|
48
|
+
}
|
|
49
|
+
callback(null, file);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (e instanceof Error) {
|
|
53
|
+
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// stream
|
|
58
|
+
if (file.isStream()) {
|
|
59
|
+
let css = "";
|
|
60
|
+
file.contents
|
|
61
|
+
.on("data", (buffer) => {
|
|
62
|
+
css += buffer.toString();
|
|
63
|
+
})
|
|
64
|
+
.on("end", async () => {
|
|
65
|
+
try {
|
|
66
|
+
const optionsGulp = {
|
|
67
|
+
...options,
|
|
68
|
+
css: [
|
|
69
|
+
{
|
|
70
|
+
raw: css,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
sourceMap: !!file.sourceMap,
|
|
74
|
+
};
|
|
75
|
+
const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
|
|
76
|
+
const purge = purgedCSSResults[0];
|
|
77
|
+
const result = optionsGulp.rejected && purge.rejected
|
|
78
|
+
? purge.rejected.join(" {}\n") + " {}"
|
|
79
|
+
: purge.css;
|
|
80
|
+
const streamResult = through();
|
|
81
|
+
streamResult.write(Buffer.from(result, "utf-8"));
|
|
82
|
+
file.contents = file.contents.pipe(streamResult);
|
|
83
|
+
// apply source map to the chain
|
|
84
|
+
if (file.sourceMap) {
|
|
85
|
+
applySourceMap(file, purge.sourceMap);
|
|
86
|
+
}
|
|
87
|
+
callback(null, file);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
if (e instanceof Error) {
|
|
91
|
+
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { gulpPurgeCSS as default };
|
package/lib/gulp-purgecss.js
CHANGED
|
@@ -1 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var glob = require('glob');
|
|
4
|
+
var PluginError = require('plugin-error');
|
|
5
|
+
var purgecss = require('purgecss');
|
|
6
|
+
var through = require('through2');
|
|
7
|
+
var applySourceMap = require('vinyl-sourcemaps-apply');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var glob__namespace = /*#__PURE__*/_interopNamespaceDefault(glob);
|
|
27
|
+
|
|
28
|
+
const PLUGIN_NAME = "gulp-purgecss";
|
|
29
|
+
function getFiles(contentArray, ignore) {
|
|
30
|
+
return contentArray.reduce((acc, content) => {
|
|
31
|
+
return [...acc, ...glob__namespace.sync(content, { ignore })];
|
|
32
|
+
}, []);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param options - options
|
|
37
|
+
* @returns
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
function gulpPurgeCSS(options) {
|
|
42
|
+
return through.obj(async function (file, _encoding, callback) {
|
|
43
|
+
// empty
|
|
44
|
+
if (file.isNull())
|
|
45
|
+
return callback(null, file);
|
|
46
|
+
// buffer
|
|
47
|
+
if (file.isBuffer()) {
|
|
48
|
+
try {
|
|
49
|
+
const optionsGulp = {
|
|
50
|
+
...options,
|
|
51
|
+
content: getFiles(options.content, options.skippedContentGlobs),
|
|
52
|
+
css: [
|
|
53
|
+
{
|
|
54
|
+
raw: file.contents.toString(),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
stdin: true,
|
|
58
|
+
sourceMap: !!file.sourceMap,
|
|
59
|
+
};
|
|
60
|
+
const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
|
|
61
|
+
const purge = purgedCSSResults[0];
|
|
62
|
+
const result = optionsGulp.rejected && purge.rejected
|
|
63
|
+
? purge.rejected.join(" {}\n") + " {}"
|
|
64
|
+
: purge.css;
|
|
65
|
+
file.contents = Buffer.from(result, "utf-8");
|
|
66
|
+
// apply source map to the chain
|
|
67
|
+
if (file.sourceMap) {
|
|
68
|
+
applySourceMap(file, purge.sourceMap);
|
|
69
|
+
}
|
|
70
|
+
callback(null, file);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
if (e instanceof Error) {
|
|
74
|
+
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// stream
|
|
79
|
+
if (file.isStream()) {
|
|
80
|
+
let css = "";
|
|
81
|
+
file.contents
|
|
82
|
+
.on("data", (buffer) => {
|
|
83
|
+
css += buffer.toString();
|
|
84
|
+
})
|
|
85
|
+
.on("end", async () => {
|
|
86
|
+
try {
|
|
87
|
+
const optionsGulp = {
|
|
88
|
+
...options,
|
|
89
|
+
css: [
|
|
90
|
+
{
|
|
91
|
+
raw: css,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
sourceMap: !!file.sourceMap,
|
|
95
|
+
};
|
|
96
|
+
const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
|
|
97
|
+
const purge = purgedCSSResults[0];
|
|
98
|
+
const result = optionsGulp.rejected && purge.rejected
|
|
99
|
+
? purge.rejected.join(" {}\n") + " {}"
|
|
100
|
+
: purge.css;
|
|
101
|
+
const streamResult = through();
|
|
102
|
+
streamResult.write(Buffer.from(result, "utf-8"));
|
|
103
|
+
file.contents = file.contents.pipe(streamResult);
|
|
104
|
+
// apply source map to the chain
|
|
105
|
+
if (file.sourceMap) {
|
|
106
|
+
applySourceMap(file, purge.sourceMap);
|
|
107
|
+
}
|
|
108
|
+
callback(null, file);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
if (e instanceof Error) {
|
|
112
|
+
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = gulpPurgeCSS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gulp-purgecss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1-alpha.0",
|
|
4
4
|
"description": "Gulp plugin for purgecss",
|
|
5
5
|
"author": "Ffloriel",
|
|
6
6
|
"homepage": "https://purgecss.com",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"test": "jest"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"glob": "^
|
|
39
|
+
"glob": "^11.0.0",
|
|
40
40
|
"plugin-error": "^2.0.0",
|
|
41
|
-
"purgecss": "^
|
|
41
|
+
"purgecss": "^7.0.1-alpha.0",
|
|
42
42
|
"through2": "^4.0.1",
|
|
43
43
|
"vinyl-sourcemaps-apply": "^0.2.1"
|
|
44
44
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"access": "public",
|
|
58
58
|
"registry": "https://registry.npmjs.org/"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5a51b05a191ba48b5e55440ac2e66822f9e182fe"
|
|
61
61
|
}
|