postcss-discard-comments 2.0.3 → 2.0.4
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/CHANGELOG.md +4 -0
- package/README.md +14 -1
- package/{index.js → dist/index.js} +31 -18
- package/{lib → dist/lib}/commentParser.js +6 -3
- package/{lib → dist/lib}/commentRemover.js +4 -2
- package/package.json +25 -10
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Discard comments in your CSS files with PostCSS.
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
## Install
|
|
6
7
|
|
|
7
8
|
With [npm](https://npmjs.org/package/postcss-discard-comments) do:
|
|
@@ -10,6 +11,7 @@ With [npm](https://npmjs.org/package/postcss-discard-comments) do:
|
|
|
10
11
|
npm install postcss-discard-comments --save
|
|
11
12
|
```
|
|
12
13
|
|
|
14
|
+
|
|
13
15
|
## Example
|
|
14
16
|
|
|
15
17
|
### Input
|
|
@@ -30,7 +32,14 @@ h1 {
|
|
|
30
32
|
|
|
31
33
|
This module discards comments from your CSS files; by default, it will remove
|
|
32
34
|
all regular comments (`/* comment */`) and preserve comments marked as important
|
|
33
|
-
(`/*! important */`)
|
|
35
|
+
(`/*! important */`).
|
|
36
|
+
|
|
37
|
+
Note that this module does not handle source map comments because they are not
|
|
38
|
+
available to it; PostCSS handles this internally, so if they are removed then
|
|
39
|
+
you will have to [configure source maps in PostCSS][maps].
|
|
40
|
+
|
|
41
|
+
[maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md
|
|
42
|
+
|
|
34
43
|
|
|
35
44
|
## API
|
|
36
45
|
|
|
@@ -85,20 +94,24 @@ console.log(postcss(comments({removeAllButFirst: true})).process(css).css);
|
|
|
85
94
|
//=> /*! heading */h1{margin:0 auto}h2{color:red}
|
|
86
95
|
```
|
|
87
96
|
|
|
97
|
+
|
|
88
98
|
## Usage
|
|
89
99
|
|
|
90
100
|
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
|
|
91
101
|
examples for your environment.
|
|
92
102
|
|
|
103
|
+
|
|
93
104
|
## Contributing
|
|
94
105
|
|
|
95
106
|
Pull requests are welcome. If you add functionality, then please add unit tests
|
|
96
107
|
to cover it.
|
|
97
108
|
|
|
109
|
+
|
|
98
110
|
## License
|
|
99
111
|
|
|
100
112
|
MIT © Ben Briggs
|
|
101
113
|
|
|
114
|
+
|
|
102
115
|
[ci]: https://travis-ci.org/ben-eb/postcss-discard-comments
|
|
103
116
|
[deps]: https://gemnasium.com/ben-eb/postcss-discard-comments
|
|
104
117
|
[npm]: http://badge.fury.io/js/postcss-discard-comments
|
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var commentParser = require('./lib/commentParser');
|
|
5
|
-
var postcss = require('postcss');
|
|
6
|
-
var space = postcss.list.space;
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
var remover = new CommentRemover(opts || {});
|
|
5
|
+
var _commentRemover = require('./lib/commentRemover');
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var _commentRemover2 = _interopRequireDefault(_commentRemover);
|
|
8
|
+
|
|
9
|
+
var _commentParser = require('./lib/commentParser');
|
|
10
|
+
|
|
11
|
+
var _commentParser2 = _interopRequireDefault(_commentParser);
|
|
12
|
+
|
|
13
|
+
var _postcss = require('postcss');
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
var space = _postcss.list.space;
|
|
18
|
+
|
|
19
|
+
exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
|
|
20
|
+
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
|
21
|
+
|
|
22
|
+
var remover = new _commentRemover2.default(opts);
|
|
23
|
+
|
|
24
|
+
function matchesComments(source) {
|
|
25
|
+
return (0, _commentParser2.default)(source).filter(function (node) {
|
|
13
26
|
return node.type === 'comment';
|
|
14
27
|
});
|
|
15
28
|
}
|
|
16
29
|
|
|
17
|
-
function replaceComments
|
|
30
|
+
function replaceComments(source) {
|
|
31
|
+
var separator = arguments.length <= 1 || arguments[1] === undefined ? ' ' : arguments[1];
|
|
32
|
+
|
|
18
33
|
if (!source) {
|
|
19
|
-
return;
|
|
34
|
+
return source;
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
separator = ' ';
|
|
23
|
-
}
|
|
24
|
-
var parsed = commentParser(source).reduce(function (value, node) {
|
|
36
|
+
var parsed = (0, _commentParser2.default)(source).reduce(function (value, node) {
|
|
25
37
|
if (node.type !== 'comment') {
|
|
26
38
|
return value + node.value;
|
|
27
39
|
}
|
|
@@ -37,7 +49,8 @@ module.exports = postcss.plugin('postcss-discard-comments', function (opts) {
|
|
|
37
49
|
return function (css) {
|
|
38
50
|
css.walk(function (node) {
|
|
39
51
|
if (node.type === 'comment' && remover.canRemove(node.text)) {
|
|
40
|
-
|
|
52
|
+
node.remove();
|
|
53
|
+
return;
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
if (node.raws.between) {
|
|
@@ -47,12 +60,11 @@ module.exports = postcss.plugin('postcss-discard-comments', function (opts) {
|
|
|
47
60
|
if (node.type === 'decl') {
|
|
48
61
|
if (node.raws.value && node.raws.value.raw) {
|
|
49
62
|
if (node.raws.value.value === node.value) {
|
|
50
|
-
|
|
51
|
-
node.value = replaced;
|
|
63
|
+
node.value = replaceComments(node.raws.value.raw);
|
|
52
64
|
} else {
|
|
53
65
|
node.value = replaceComments(node.value);
|
|
54
66
|
}
|
|
55
|
-
|
|
67
|
+
node.raws.value = null;
|
|
56
68
|
}
|
|
57
69
|
if (node.raws.important) {
|
|
58
70
|
node.raws.important = replaceComments(node.raws.important);
|
|
@@ -83,3 +95,4 @@ module.exports = postcss.plugin('postcss-discard-comments', function (opts) {
|
|
|
83
95
|
});
|
|
84
96
|
};
|
|
85
97
|
});
|
|
98
|
+
module.exports = exports['default'];
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = commentParser;
|
|
5
|
+
function commentParser(input) {
|
|
4
6
|
var tokens = [];
|
|
5
7
|
var length = input.length;
|
|
6
8
|
var pos = 0;
|
|
7
|
-
var next;
|
|
9
|
+
var next = undefined;
|
|
8
10
|
|
|
9
11
|
while (pos < length) {
|
|
10
12
|
next = input.indexOf('/*', pos);
|
|
@@ -17,7 +19,7 @@ module.exports = function (input) {
|
|
|
17
19
|
pos = next;
|
|
18
20
|
|
|
19
21
|
next = input.indexOf('*/', pos + 2);
|
|
20
|
-
if (
|
|
22
|
+
if (! ~next) {
|
|
21
23
|
throw new Error('postcss-discard-comments: Unclosed */');
|
|
22
24
|
}
|
|
23
25
|
tokens.push({
|
|
@@ -36,3 +38,4 @@ module.exports = function (input) {
|
|
|
36
38
|
|
|
37
39
|
return tokens;
|
|
38
40
|
};
|
|
41
|
+
module.exports = exports['default'];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
function CommentRemover(options) {
|
|
4
5
|
this.options = options;
|
|
5
6
|
}
|
|
6
7
|
|
|
@@ -23,4 +24,5 @@ CommentRemover.prototype.canRemove = function (comment) {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
exports.default = CommentRemover;
|
|
28
|
+
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-discard-comments",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Discard comments in your CSS files with PostCSS.",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"index.js",
|
|
7
|
+
"dist",
|
|
9
8
|
"LICENSE-MIT"
|
|
10
9
|
],
|
|
11
10
|
"scripts": {
|
|
12
|
-
"
|
|
11
|
+
"pretest": "eslint src",
|
|
12
|
+
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
|
|
13
|
+
"test": "ava src/__tests__"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"css",
|
|
@@ -19,10 +20,18 @@
|
|
|
19
20
|
],
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
23
|
+
"ava": "^0.11.0",
|
|
24
|
+
"babel-cli": "^6.5.1",
|
|
25
|
+
"babel-core": "^6.5.1",
|
|
26
|
+
"babel-plugin-add-module-exports": "^0.1.2",
|
|
27
|
+
"babel-preset-es2015": "^6.5.0",
|
|
28
|
+
"babel-preset-es2015-loose": "^7.0.0",
|
|
29
|
+
"babel-preset-stage-0": "^6.5.0",
|
|
30
|
+
"del-cli": "^0.2.0",
|
|
31
|
+
"eslint": "^1.10.3",
|
|
32
|
+
"eslint-config-cssnano": "^1.0.0",
|
|
33
|
+
"postcss-scss": "^0.1.3",
|
|
34
|
+
"postcss-simple-vars": "^1.2.0"
|
|
26
35
|
},
|
|
27
36
|
"homepage": "https://github.com/ben-eb/postcss-discard-comments",
|
|
28
37
|
"author": {
|
|
@@ -32,6 +41,12 @@
|
|
|
32
41
|
},
|
|
33
42
|
"repository": "ben-eb/postcss-discard-comments",
|
|
34
43
|
"dependencies": {
|
|
35
|
-
"postcss": "^5.0.
|
|
44
|
+
"postcss": "^5.0.14"
|
|
45
|
+
},
|
|
46
|
+
"ava": {
|
|
47
|
+
"require": "babel-core/register"
|
|
48
|
+
},
|
|
49
|
+
"eslintConfig": {
|
|
50
|
+
"extends": "cssnano"
|
|
36
51
|
}
|
|
37
52
|
}
|