Skip to content

Commit

Permalink
Merge pull request #226 from alundiak/219-pr-suggestion
Browse files Browse the repository at this point in the history
'Support both csso v1 and v2' - Improved code in handling csso optimization function (justDoIt vs. minify)
  • Loading branch information
alundiak authored Feb 19, 2017
2 parents 1778912 + 0e67d61 commit 07e4c0d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
46 changes: 46 additions & 0 deletions compatibility-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# To cover all possible use case, you should change `optimizeCss` in `example/build.js` from "none" to
# optimizeCss: "standard.keepLines"
# optimizeCss: "standard.keepWhitespace"
# optimizeCss: "standard.keepComments"
# optimizeCss: "standard.keepComments.keepLines"
# optimizeCss: "standard.keepLines.keepWhitespace" - default by r.js

(
npm install requirejs@2.1.10 -g

npm install csso@1.3.12 -g
r.js -o example/build.js

npm install csso@1.4.0 -g
r.js -o example/build.js

npm install csso@1.8.0 -g
r.js -o example/build.js

npm install csso@2.0.0 -g
r.js -o example/build.js

npm install csso@latest -g
r.js -o example/build.js

# RequireJS@latest

npm install requirejs@latest -g

npm install csso@1.3.12 -g
r.js -o example/build.js

npm install csso@1.4.0 -g
r.js -o example/build.js

npm install csso@1.8.0 -g
r.js -o example/build.js

npm install csso@2.0.0 -g
r.js -o example/build.js

npm install csso@latest -g
r.js -o example/build.js
) > compatibility.log
11 changes: 10 additions & 1 deletion css-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ define(['require', './normalize'], function(req, normalize) {
}
var csslen = css.length;
try {
css = csso.justDoIt(css);
if (typeof csso.minify === 'function') {
var minifyResult = csso.minify(css);
if (typeof minifyResult === 'string'){ // for csso < 2.0.0
css = minifyResult;
} else if (typeof minifyResult === 'object'){ // for csso >= 2.0.0
css = minifyResult.css;
}
} else { // justDoIt() was always. minify() appeared in csso 1.4.0.
css = csso.justDoIt(css);
}
}
catch(e) {
console.log('Compression failed due to a CSS syntax error.');
Expand Down

0 comments on commit 07e4c0d

Please sign in to comment.