New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aofl/html-webpack-purify-internal-css-plugin

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aofl/html-webpack-purify-internal-css-plugin - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0-alpha.0

64

modules/purify-internal-style/index.js
const parse5 = require('parse5');
const purify = require('purify-css');
const Purgecss = require('purgecss');

@@ -39,3 +39,22 @@ /**

/**
*
* @param {Object} docFrag
* @return {Array}
*/
const getScriptNodes = async (docFrag) => {
const scripts = [];
await traverseChildNodes(docFrag, (docFrag) => {
if (docFrag.tagName === 'script' && Array.isArray(docFrag.childNodes)) {
for (let i = 0; i < docFrag.childNodes.length; i++) {
scripts.push(docFrag.childNodes[i]);
}
}
});
return scripts;
};
/**

@@ -47,3 +66,3 @@ *

*/
const getStlyeFreeHtml = (document, styles) => {
const getStyleFreeHtml = (document, styles, scripts) => {
for (let i = 0; i < styles.length; i++) {

@@ -55,2 +74,8 @@ const style = styles[i];

for (let i = 0; i < scripts.length; i++) {
const script = scripts[i];
script.cachedValue = script.value;
script.value = '';
}
const stlyeFreeHtml = parse5.serialize(document);

@@ -64,2 +89,7 @@

for (let i = 0; i < scripts.length; i++) {
const script = scripts[i];
script.value = script.cachedValue;
delete script.cachedValue;
}
return stlyeFreeHtml;

@@ -74,11 +104,24 @@ };

*/
const purifyStyles = async (html, styles, options) => {
const purifyStyles = (html, styles, options) => {
for (let i = 0; i < styles.length; i++) {
const style = styles[i];
await new Promise((resolve) => {
purify(html, style.value, options, (purified) => {
style.value = purified;
resolve();
});
const purgeCss = new Purgecss({
content: [
{
raw: html,
extension: 'html'
}
],
css: [
{
raw: style.value
}
],
rejected: false,
...options
});
const purged = purgeCss.purge();
style.value = purged[0].css;
}

@@ -90,4 +133,5 @@ };

getStyleNodes,
getStlyeFreeHtml,
purifyStyles
getStyleFreeHtml,
purifyStyles,
getScriptNodes
};

26

modules/purifycss-plugin/index.js
const parse5 = require('parse5');
const {getStyleNodes, purifyStyles, getStlyeFreeHtml} = require('../purify-internal-style');
const {getStyleNodes, purifyStyles, getStyleFreeHtml, getScriptNodes} = require('../purify-internal-style');
const defaultsDeep = require('lodash.defaultsdeep');

@@ -60,16 +60,20 @@

.tapAsync(PurifycssPlugin.name + '#befeHtmlGeneration', async (data, cb) => {
const document = parse5.parse(data.html);
try {
if (this.options.level !== 'none') {
const document = parse5.parse(data.html);
const styles = await getStyleNodes(document);
const scripts = await getScriptNodes(document);
let html = '';
if (this.options.level === 'auto') {
html = getStyleFreeHtml(document, styles, scripts);
}
if (this.options.level !== 'none') {
const styles = await getStyleNodes(document);
let html = '';
if (this.options.level === 'auto') {
html = getStlyeFreeHtml(document, styles);
await purifyStyles(html, styles, this.options.purgeCss);
data.html = parse5.serialize(document);
}
await purifyStyles(html, styles, this.options.purifyCSS);
cb(null, data);
} catch (e) {
cb(e);
}
data.html = parse5.serialize(document);
cb(null, data);
});

@@ -76,0 +80,0 @@ });

{
"name": "@aofl/html-webpack-purify-internal-css-plugin",
"version": "2.0.0",
"version": "2.1.0-alpha.0",
"description": "",

@@ -20,7 +20,7 @@ "main": "index.js",

"dependencies": {
"lodash.defaultsdeep": "^4.6.0",
"lodash.defaultsdeep": "^4.6.1",
"parse5": "^5.1.0",
"purify-css": "^1.2.5"
"purgecss": "^1.3.0"
},
"gitHead": "91b9b3074f7031a51ce7afa9b542ff5dcfd64997"
"gitHead": "f3d01e2e352befb804bfb3549b9e9cb861099541"
}

@@ -35,3 +35,3 @@ # @aofl/html-webpack-purify-internal-css-plugin

| --------- | --------------------------------------------------------------------------------------------------------------- |
| auto | This is the default behavior. It prunes unused css rules based on the generated html and the purifyCss options. |
| auto | This is the default behavior. It prunes unused css rules based on the generated html and the purgeCss options. |
| whitelist | Only keep whitelisted rules. |

@@ -53,15 +53,6 @@ | all | Prune everything |

### purifyCSS
### purgeCss
[PurifyCSS options](https://github.com/purifycss/purifycss#properties-of-options-object)
[purgeCss options](https://www.npmjs.com/package/purgecss)
| Option | Description | default |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| minify | Set to true to minify | false |
| output | Filepath to write purified CSS to. Returns raw string | Always false |
| info | Logs info on how much CSS was removed | false |
| rejected | Logs the CSS rules that were removed if `true` | false |
| whitelist | Array of selectors to always leave in. Ex. ['button-active', '*modal*'] this will leave any selector that includes modal in it and selectors that match button-active. (wrapping the string with \*'s, leaves all selectors that include it) | [] |
<!-- prettier-ignore -->
```javascript

@@ -73,8 +64,9 @@ module.export = {

level: process.env.NODE_ENV === 'development'? 'none': 'auto',
purifyCSS: {
info: true,
rejected: true,
whitelist: [
'.♥'
]
purgeCss: {
whitelist?: Array<string>,
whitelistPatterns?: Array<RegExp>,
whitelistPatternsChildren?: Array<RegExp>,
keyframes?: boolean,
fontFace?: boolean,
rejected?: boolean
}

@@ -81,0 +73,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc