Skip to content

Commit 230ddf8

Browse files
committed
initial commit
0 parents  commit 230ddf8

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Jan Nicklas
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const assert = require('assert');
3+
const cheerio = require('cheerio');
4+
const uncss = require('uncss');
5+
6+
function HtmlWebpackUncssPlugin (options) {
7+
assert.equal(options, undefined, 'The HtmlWebpackUncssPlugin does not accept any options');
8+
}
9+
10+
HtmlWebpackUncssPlugin.prototype.apply = (compiler) => {
11+
compiler.plugin('compilation', function(compilation) {
12+
compilation.plugin('html-webpack-plugin-after-html-processing', function(htmlPluginData, callback) {
13+
const $ = cheerio.load(htmlPluginData.html);
14+
const styles = [];
15+
$('style').each(function() {
16+
const style = $(this).html();
17+
if (style) {
18+
styles.push(style);
19+
}
20+
});
21+
22+
uncss($.html(), { raw: styles.join(' ') }, (error, output) => {
23+
if (error) {
24+
return callback(error);
25+
}
26+
$('style').text(output);
27+
htmlPluginData.html = $.html();
28+
return callback(null, htmlPluginData);
29+
});
30+
});
31+
});
32+
};
33+
34+
module.exports = HtmlWebpackUncssPlugin;

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "html-webpack-uncss-plugin",
3+
"version": "1.0.0",
4+
"description": "Remove unused embedded styles",
5+
"main": "index.js",
6+
"files": [
7+
"index.js"
8+
],
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/csabapalfi/html-webpack-uncss-plugin.git"
12+
},
13+
"keywords": [
14+
"webpack",
15+
"plugin",
16+
"html-webpack-plugin",
17+
"uncss",
18+
"styles"
19+
],
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/csabapalfi/html-webpack-uncss-plugin/issues"
23+
},
24+
"homepage": "https://github.com/csabapalfi/html-webpack-uncss-plugin",
25+
"dependencies": {
26+
"cheerio": "^0.22.0",
27+
"uncss": "^0.14.1"
28+
}
29+
}

0 commit comments

Comments
 (0)