Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transform callback #863

Closed
jakubpawlowicz opened this issue Jan 19, 2017 · 1 comment
Closed

Add transform callback #863

jakubpawlowicz opened this issue Jan 19, 2017 · 1 comment
Milestone

Comments

@jakubpawlowicz
Copy link
Collaborator

See #842 (comment)


Here's one more idea for 4.0 - what if you could pass a callback as an option to transform any property? This would solve:

  • rewriting / resolving URLs as one could update them by hand if nothing else works
  • dropping properties if needed
  • rewriting some values if needed

For example:

new CleanCSS({
  transformProperty: function (name, value) {
    if (name == 'background-image' && value.indexOf('invalid/path') > -1) {
      return value.replace('invalid/path', 'valid/path');
    }
  }
}).minify(...)

or

new CleanCSS({
  transformProperty: function (name, value) {
    if (name.indexOf('-o-') === 0) {
      return false; // drop a property
    }
  }
}).minify(...)
@jakubpawlowicz
Copy link
Collaborator Author

To be consistent with other level 1 optimizations it should rather be:

new CleanCSS({
  level: {
    1: {
      transform: function (propertName, propertyValue) {
        if (name == 'background-image' && value.indexOf('invalid/path') > -1) {
          return value.replace('invalid/path', 'valid/path');
        }
      }
    }
  }
}).minify(...)

@jakubpawlowicz jakubpawlowicz changed the title Add transformProperty callback Add transform callback Jan 19, 2017
jakubpawlowicz added a commit that referenced this issue Jan 19, 2017
Why:

* So users can apply custom optimizations without forking clean-css
  and learning how to plug such optimization in;
* may also aid in rewriting URLs after introduction of `rebaseTo`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant