segmentio / myth

A CSS preprocessor that acts like a polyfill for future versions of the spec.
4.32k stars 131 forks source link

Passing options to autoprefixer #16

Closed cvn closed 10 years ago

cvn commented 10 years ago

Is there a way to pass options to autoprefixer? I don't see it in the docs. Autoprefixer accepts arguments like so:

autoprefixer("last 1 version", "> 1%", "ie 8", "ie 7")
ianstormtaylor commented 10 years ago

i've considered adding options, hadn't implemented it yet though. curious though, which option are you looking to pass?

cvn commented 10 years ago

I'm looking to pass target browsers, like in the example above. I believe these are the only options autoprefixer accepts.

ianstormtaylor commented 10 years ago

oh yeah sorry, i just meant whats the browser support you are trying to achieve? and for what reason? :) just trying to understand the use case to see if there's a good way to handle it with an abstraction

cvn commented 10 years ago

This is what I currently use: 'last 2 versions', 'ff 15', 'ios 3.2', 'android 2.3', 'ie 8'

Mostly this gives me more old -moz and -webkit properties, and enables support on older gear (older iOS and Android devices, old builds of firefox bundled with CentOS, etc). Since autoprefixer makes maintaining these additional prefixes more or less free, I figure why not.

necolas commented 10 years ago

yeah, that's something we (twitter) wanted and provided for in rework-suit. pretty handy, especially if you need a more explicit support matrix that the autoprefixer defaults.

ianstormtaylor commented 10 years ago

yeah might not be able to get out of it then. it definitely makes sense. i just wish the abbreviations for browser names were expanded. i think thats the part that makes me think the api is ugly and makes me want to avoid it

ianstormtaylor commented 10 years ago

k im thinking the api would be:

myth(css, { 
  browsers: [] 
});

since that leaves us open for stuff like:

myth(css, { 
  browsers: [],
  compress: true
});

and the rework exposed function could even take the same ones too:

myth({ 
  browsers: [],
  compress: true
});
basiclines commented 10 years ago

+1 to this feature, if want to generate my css files only for modern browsers i might don't want calc() expression to be generated as a plain amount in px

cvn commented 10 years ago

@basiclines this issue doesn't affect calc() translation. This is specifically for autoprefixer, which only controls vendor prefixes, e.g. -webkit-, -moz-, etc.

jimkang commented 10 years ago

Another +1. Here's my use case: When I use "display: flex", I do not want "display: -webkit-box" added. -webkit-box applies on iOS 6 Safari and older, however, in my case, it just makes things worse because it doesn't implement any form of flex-wrap. I'd rather just not have it at all.

cvn commented 10 years ago

@ianstormtaylor Expanded browser names are now supported by Autoprefixer, not sure if that changes your opinion of the API.

gasolin commented 10 years ago

FYI, adobe resin (also based on rework) allows to pass browsers option while calling the function https://github.com/topcoat/resin

output = resin({
    // Pass it a css file to process
    src: 'src/entry.css',
    // Tell it what browsers to prefix for
    browsers: ['last 1 version', 'ios', 'android 4'] 
});

write('path/to/output/dir/filename.css', output);

compare to myth

var css = fs.readFileSync('index.css', 'utf8');
var output = myth(css);

fs.writeFileSync('converted.css', output);

I'd prefer resin-like API instead of

myth(css, { 
  browsers: [],
  compress: true
});
ianstormtaylor commented 10 years ago

added in 1.0.0! thanks