Support both csso v1 and v2 - #219
Conversation
| try { | ||
| css = csso.justDoIt(css); | ||
| if (typeof csso.minify === 'function') { | ||
| css = csso.minify(css).css; |
There was a problem hiding this comment.
Really, csso v2.3.1 has minify() function output result in this form:
result = debugOutput('translate', options, Date.now(), {
css: translate(compressResult.ast),
map: null
});
Need to test require.css for 2 possible ways: minify(css) and minify(css).css
There was a problem hiding this comment.
I checked this code changes in regards to csso versions: 1.8.0, 2.0.0 and 2.3.1. And suggested code not always works correctly.
Suggested code (csso.minify(css).css) will cause error in case of usage csso v1.8.0
Error: TypeError: Cannot read property 'length' of undefined
at compress (eval at <anonymous> (/usr/local/lib/node_modules/requirejs/bin/r.js:25271:33), <anonymous>:50:63)
Note: tested with requirejs v 2.1.10 (as bundled in require-css) and 2.3.2 (as latest)
So we need to improve code a bit, so that to support at least 3 major versions.
I will provide a comment a bit later, or create my own PR.
|
I did deep research of how your suggested change can affect potential end customers/consumers of And here is my code change suggestion: try {
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);
}
}I did this, because I know enterprise projects, which still use old version of require-css and csso, so my approach is universal. Tested with:
Note: I realize, this change may be overthinking/overcomplex, but so far the fact is - if we merge ur current code change, someone who will upgrade to new So @prantlf please consider my code above as a suggestion to apply to your PR. After 1 week silence, I will close this PR, and recreate new one with my suggested code. cc/ @guybedford |
No description provided.