Skip to content

Commit 8ef7002

Browse files
authored
Merge pull request #37 from derTobsch/upgrade-clean-css
Upgrade clean css and add basic tests
2 parents 823c04e + d6d797f commit 8ef7002

File tree

10 files changed

+1935
-28
lines changed

10 files changed

+1935
-28
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# @see http://editorconfig.org/
2+
3+
# the buck stops here
4+
root = true
5+
6+
# all files
7+
[*]
8+
end_of_line = LF
9+
indent_style = space
10+
indent_size = 4
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
[{*.yml,*.yaml}]
16+
indent_size = 2

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: setup node 20
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: "20"
19+
cache: 'npm'
20+
- run: npm ci
21+
- run: npm test

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@ Compresses the css output from less using [clean-css](https://github.com/jakubpa
66

77
## lessc usage
88

9+
First of all install less via
10+
11+
```bash
12+
npm install -g less
913
```
14+
15+
then install the `less-plugin-clean-css`
16+
17+
```bash
1018
npm install -g less-plugin-clean-css
1119
```
1220

1321
and then on the command line,
1422

15-
```
23+
```bash
1624
lessc file.less --clean-css="--s1 --advanced --compatibility=ie8"
1725
```
1826

19-
See [clean-css](https://github.com/jakubpawlowicz/clean-css/tree/v3.0.1#how-to-use-clean-css-programmatically) for the available command options - the only differences are `advanced` and `rebase` which we default to false, because it is not always entirely safe.
27+
See [clean-css](https://github.com/jakubpawlowicz/clean-css/tree/v3.0.1#how-to-use-clean-css-programmatically) for the
28+
available command options - the only differences are `advanced` and `rebase` which we default to false, because it is
29+
not always entirely safe.
2030

2131
## Programmatic usage
2232

2333
```js
2434
var LessPluginCleanCSS = require('less-plugin-clean-css'),
2535
cleanCSSPlugin = new LessPluginCleanCSS({advanced: true});
26-
less.render(lessString, { plugins: [cleanCSSPlugin] })
27-
.then(
36+
less.render(lessString, {plugins: [cleanCSSPlugin]})
37+
.then(
2838
```
2939
3040
## Browser usage

lib/clean-css-processor.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"use strict";
22

3-
var CleanCSS = require("clean-css");
3+
const CleanCSS = require("clean-css");
44

5-
module.exports = function() {
5+
module.exports = function () {
66
function CleanCSSProcessor(options) {
77
this.options = options || {};
88
}
99

1010
CleanCSSProcessor.prototype = {
1111
process: function (css, extra) {
12-
var options = this.options,
12+
let options = this.options,
1313
sourceMap = extra.sourceMap,
1414
sources,
1515
sourcesContent;
@@ -18,7 +18,7 @@ module.exports = function() {
1818
options.sourceMap = sourceMap.getExternalSourceMap();
1919
if (options.sourceMap) {
2020
options.sourceMap = options.sourceMap.toString();
21-
var sourceMapObj = JSON.parse(options.sourceMap);
21+
const sourceMapObj = JSON.parse(options.sourceMap);
2222
if (sourceMapObj.sourcesContent) {
2323
sourcesContent = sourceMapObj.sourcesContent;
2424
sources = sourceMapObj.sources;
@@ -39,24 +39,24 @@ module.exports = function() {
3939
options.advanced = false;
4040
}
4141

42-
var output = new CleanCSS(options).minify(css);
42+
const output = new CleanCSS(options).minify(css);
4343

4444
if (sourceMap) {
4545
if (sourcesContent) {
46-
for (var source = 0; source < sources.length; source++) {
46+
for (let source = 0; source < sources.length; source++) {
4747
output.sourceMap.setSourceContent(sources[source], sourcesContent[source]);
4848
}
4949
}
5050
sourceMap.setExternalSourceMap(JSON.stringify(output.sourceMap));
5151
}
5252

53-
var css = output.styles;
53+
let outputCSS = output.styles;
5454
if (sourceMap) {
55-
var sourceMapURL = sourceMap.getSourceMapURL();
56-
css += sourceMap.getCSSAppendage();
55+
const sourceMapURL = sourceMap.getSourceMapURL();
56+
outputCSS += sourceMap.getCSSAppendage();
5757
}
5858

59-
return css;
59+
return outputCSS;
6060
}
6161
};
6262

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
var getCleanCSSProcessor = require("./clean-css-processor"),
3+
const getCleanCSSProcessor = require("./clean-css-processor"),
44
usage = require("./usage"),
55
parseOptions = require("./parse-options");
66

@@ -9,14 +9,14 @@ function LessPluginCleanCSS(options) {
99
}
1010

1111
LessPluginCleanCSS.prototype = {
12-
install: function(less, pluginManager) {
13-
var CleanCSSProcessor = getCleanCSSProcessor(less);
12+
install: function (less, pluginManager) {
13+
const CleanCSSProcessor = getCleanCSSProcessor(less);
1414
pluginManager.addPostProcessor(new CleanCSSProcessor(this.options));
1515
},
1616
printUsage: function () {
1717
usage.printUsage();
1818
},
19-
setOptions: function(options) {
19+
setOptions: function (options) {
2020
this.options = parseOptions(options);
2121
},
2222
minVersion: [2, 1, 0]

lib/parse-options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use strict";
22

3-
module.exports = function(options) {
3+
module.exports = function (options) {
44
if (typeof options === "string") {
5-
var cleanOptionArgs = options.split(" ");
5+
const cleanOptionArgs = options.split(" ");
66
options = {};
77

8-
for (var i = 0; i < cleanOptionArgs.length; i++) {
9-
var argSplit = cleanOptionArgs[i].split("="),
8+
for (let i = 0; i < cleanOptionArgs.length; i++) {
9+
const argSplit = cleanOptionArgs[i].split("="),
1010
argName = argSplit[0].replace(/^-+/, "");
1111

1212
switch (argName) {
@@ -21,7 +21,7 @@ module.exports = function(options) {
2121
options.keepSpecialComments = 1;
2222
break;
2323
case "keepSpecialComments":
24-
var specialCommentOption = argSplit[1];
24+
let specialCommentOption = argSplit[1];
2525
if (specialCommentOption !== "*") {
2626
specialCommentOption = Number(specialCommentOption);
2727
}

lib/usage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
module.exports = {
4-
printUsage: function() {
4+
printUsage: function () {
55
console.log("");
66
console.log("Clean CSS Plugin");
77
console.log("specify plugin with --clean-css");
@@ -13,7 +13,7 @@ module.exports = {
1313
this.printOptions();
1414
console.log("");
1515
},
16-
printOptions: function() {
16+
printOptions: function () {
1717
console.log("we support the following arguments... 'keep-line-breaks', 'b'");
1818
console.log("'s0', 's1', 'advanced', 'rebase', 'keepSpecialComments', compatibility', 'rounding-precision'");
1919
console.log("'skip-aggressive-merging', 'skip-shorthand-compacting'");

0 commit comments

Comments
 (0)