Code Monkey home page Code Monkey logo

autoprefixer's Introduction

PostCSS

Philosopher’s stone, logo of PostCSS

PostCSS is a tool for transforming styles with JS plugins. These plugins can lint your CSS, support variables and mixins, transpile future CSS syntax, inline images, and more.

PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba, and JetBrains. The Autoprefixer and Stylelint PostCSS plugins is one of the most popular CSS tools.


  Made in Evil Martians, product consulting for developer tools.


Sponsorship

PostCSS needs your support. We are accepting donations at Open Collective.

Sponsored by Tailwind CSS        Sponsored by ThemeIsle

Plugins

PostCSS takes a CSS file and provides an API to analyze and modify its rules (by transforming them into an Abstract Syntax Tree). This API can then be used by plugins to do a lot of useful things, e.g., to find errors automatically, or to insert vendor prefixes.

Currently, PostCSS has more than 200 plugins. You can find all of the plugins in the plugins list or in the searchable catalog. Below is a list of our favorite plugins — the best demonstrations of what can be built on top of PostCSS.

If you have any new ideas, PostCSS plugin development is really easy.

Solve Global CSS Problem

  • postcss-use allows you to explicitly set PostCSS plugins within CSS and execute them only for the current file.
  • postcss-modules and react-css-modules automatically isolate selectors within components.
  • postcss-autoreset is an alternative to using a global reset that is better for isolatable components.
  • postcss-initial adds all: initial support, which resets all inherited styles.
  • cq-prolyfill adds container query support, allowing styles that respond to the width of the parent.

Use Future CSS, Today

Better CSS Readability

Images and Fonts

Linters

  • stylelint is a modular stylesheet linter.
  • stylefmt is a tool that automatically formats CSS according stylelint rules.
  • doiuse lints CSS for browser support, using data from Can I Use.
  • colorguard helps you maintain a consistent color palette.

Other

  • cssnano is a modular CSS minifier.
  • lost is a feature-rich calc() grid system.
  • rtlcss mirrors styles for right-to-left locales.

Syntaxes

PostCSS can transform styles in any syntax, not just CSS. If there is not yet support for your favorite syntax, you can write a parser and/or stringifier to extend PostCSS.

  • sugarss is a indent-based syntax like Sass or Stylus.
  • postcss-syntax switch syntax automatically by file extensions.
  • postcss-html parsing styles in <style> tags of HTML-like files.
  • postcss-markdown parsing styles in code blocks of Markdown files.
  • postcss-styled-syntax parses styles in template literals CSS-in-JS like styled-components.
  • postcss-jsx parsing CSS in template / object literals of source files.
  • postcss-styled parsing CSS in template literals of source files.
  • postcss-scss allows you to work with SCSS (but does not compile SCSS to CSS).
  • postcss-sass allows you to work with Sass (but does not compile Sass to CSS).
  • postcss-less allows you to work with Less (but does not compile LESS to CSS).
  • postcss-less-engine allows you to work with Less (and DOES compile LESS to CSS using true Less.js evaluation).
  • postcss-js allows you to write styles in JS or transform React Inline Styles, Radium or JSS.
  • postcss-safe-parser finds and fixes CSS syntax errors.
  • midas converts a CSS string to highlighted HTML.

Articles

More articles and videos you can find on awesome-postcss list.

Books

Usage

You can start using PostCSS in just two steps:

  1. Find and add PostCSS extensions for your build tool.
  2. Select plugins and add them to your PostCSS process.

CSS-in-JS

The best way to use PostCSS with CSS-in-JS is astroturf. Add its loader to your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'postcss-loader'],
      },
      {
        test: /\.jsx?$/,
        use: ['babel-loader', 'astroturf/loader'],
      }
    ]
  }
}

Then create postcss.config.js:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Parcel

Parcel has built-in PostCSS support. It already uses Autoprefixer and cssnano. If you want to change plugins, create postcss.config.js in project’s root:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Parcel will even automatically install these plugins for you.

Please, be aware of the several issues in Version 1. Notice, Version 2 may resolve the issues via issue #2157.

Webpack

Use postcss-loader in webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
            }
          },
          {
            loader: 'postcss-loader'
          }
        ]
      }
    ]
  }
}

Then create postcss.config.js:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Gulp

Use gulp-postcss and gulp-sourcemaps.

gulp.task('css', () => {
  const postcss    = require('gulp-postcss')
  const sourcemaps = require('gulp-sourcemaps')

  return gulp.src('src/**/*.css')
    .pipe( sourcemaps.init() )
    .pipe( postcss([ require('autoprefixer'), require('postcss-nested') ]) )
    .pipe( sourcemaps.write('.') )
    .pipe( gulp.dest('build/') )
})

npm Scripts

To use PostCSS from your command-line interface or with npm scripts there is postcss-cli.

postcss --use autoprefixer -o main.css css/*.css

Browser

If you want to compile CSS string in browser (for instance, in live edit tools like CodePen), just use Browserify or webpack. They will pack PostCSS and plugins files into a single file.

To apply PostCSS plugins to React Inline Styles, JSS, Radium and other CSS-in-JS, you can use postcss-js and transforms style objects.

const postcss  = require('postcss-js')
const prefixer = postcss.sync([ require('autoprefixer') ])

prefixer({ display: 'flex' }) //=> { display: ['-webkit-box', '-webkit-flex', '-ms-flexbox', 'flex'] }

Runners

JS API

For other environments, you can use the JS API:

const autoprefixer = require('autoprefixer')
const postcss = require('postcss')
const postcssNested = require('postcss-nested')
const fs = require('fs')

fs.readFile('src/app.css', (err, css) => {
  postcss([autoprefixer, postcssNested])
    .process(css, { from: 'src/app.css', to: 'dest/app.css' })
    .then(result => {
      fs.writeFile('dest/app.css', result.css, () => true)
      if ( result.map ) {
        fs.writeFile('dest/app.css.map', result.map.toString(), () => true)
      }
    })
})

Read the PostCSS API documentation for more details about the JS API.

All PostCSS runners should pass PostCSS Runner Guidelines.

Options

Most PostCSS runners accept two parameters:

  • An array of plugins.
  • An object of options.

Common options:

  • syntax: an object providing a syntax parser and a stringifier.
  • parser: a special syntax parser (for example, SCSS).
  • stringifier: a special syntax output generator (for example, Midas).
  • map: source map options.
  • from: the input file name (most runners set it automatically).
  • to: the output file name (most runners set it automatically).

Treat Warnings as Errors

In some situations it might be helpful to fail the build on any warning from PostCSS or one of its plugins. This guarantees that no warnings go unnoticed, and helps to avoid bugs. While there is no option to enable treating warnings as errors, it can easily be done by adding postcss-fail-on-warn plugin in the end of PostCSS plugins:

module.exports = {
  plugins: [
    require('autoprefixer'),
    require('postcss-fail-on-warn')
  ]
}

Editors & IDE Integration

VS Code

Sublime Text

Vim

WebStorm

To get support for PostCSS in WebStorm and other JetBrains IDEs you need to install this plugin.

Security Contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

For Enterprise

Available as part of the Tidelift Subscription.

The maintainers of postcss and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

autoprefixer's People

Contributors

aaron3 avatar ai avatar ben-eb avatar bogdan0083 avatar coliff avatar cornbreadcompanion avatar cvle avatar cvn avatar dan503 avatar fanich37 avatar gucong3000 avatar heady avatar iamvdo avatar janczer avatar kieranju avatar kossnocorp avatar lukewarlow avatar lydell avatar moox avatar nschonni avatar porada avatar regularlabs avatar romainmenke avatar semigradsky avatar stevemao avatar sukkaw avatar taritsyn avatar trevorah avatar yepninja avatar yisibl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autoprefixer's Issues

[autoprefixer-rails] Conflict with `turbo-sprockets-rails3`

So, I have such part in my Gemfile (exact copy):

group :assets do
  gem 'oily_png'

  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier',     '~> 1.3.0'

  gem 'compass-rails'
  gem 'handlebars_assets', '= 0.8.2'

  gem 'sass-mediaqueries-rails'
  gem 'autoprefixer-rails'

  gem 'turbo-sprockets-rails3'
end

In development everything works like a charm, but if I try to run rake assets:precompile (or deploy an app with Capistrano) i get:

% rake assets:precompile
/usr/local/opt/rbenv/versions/2.0.0-p195/bin/ruby /usr/local/opt/rbenv/versions/2.0.0-p195/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
TypeError: Cannot call method 'map' of undefined
  (in /Users/kavu/Work/my_app/app/assets/stylesheets/application.scss) 

My application.scss is a bunch of SCSS @imports.

Commenting out gem 'turbo-sprockets-rails3' solves the problem.

Support for ::selection

::selection {
    transition: color 0.1s ease-out;
    color: blue;
}

⬇️

::-moz-selection {
    -webkit-transition: color 0.1s ease-out;
    transition: color 0.1s ease-out;
    color: blue;
}

::selection {
    -webkit-transition: color 0.1s ease-out;
    transition: color 0.1s ease-out;
    color: blue;
}

According to MDN, Firefox doesn’t support unprefixed ::selection selector. Other browsers either support the unprefixed version or don’t support the selector at all, so it’s safe to assume that only the -moz- prefix will be needed in the near future.

Unfortunately, this is not covered in Can I Use data (yet).

I was planning to make a pull request for it, but the current architecture doesn’t seem to allow for inserting new selectors easily.

-moz-linear-gradient

autoprefixer.compile('body { background: linear-gradient(top, #809e2e 0%, #bbce62 42%, #8aa73b 62%, #638e09 100%); }')

compiles to:

body {
  background: -webkit-linear-gradient(top, #809e2e 0%, #bbce62 42%, #8aa73b 62%, #638e09 100%)
  background: linear-gradient(top, #809e2e 0%, #bbce62 42%, #8aa73b 62%, #638e09 100%);
}

It could just be my lack of understanding of how linear-gradient works, but I was expecting -moz-linear-gradient in there too? i.e. this looks fine in Firefox:

moz-linear-gradient(center top , #FFFFFF 0%, #DBDEDE 15%, #545D5C 35%, #636C6A 50%, #E7ECE8 70%, #E9EAE9 87%, #AEAEB2 100%) repeat scroll 0 0 transparent

using node/npm verison.

Prefixed properties and values

I know it is a complicated case, but if I have this code:

perspective: calc(50em + 15px);

I would like to have something like this:

-webkit-perspective: -webkit-calc(50em + 15px);
-moz-perspective: -moz-calc(50em + 15px);
-moz-perspective: calc(50em + 15px);
perspective: -webkit-calc(50em + 15px);
perspective: calc(50em + 15px);

But instead result is:

perspective: calc(50em + 15px); /* This line shouldn't be first */
-webkit-perspective: -webkit-calc(50em + 15px);
-ms-perspective: -webkit-calc(50em + 15px); /* -ms vs. -webkit and `perspective` is supported unprefixed in IE 10 and later */
-o-perspective: -webkit-calc(50em + 15px); /* -o vs. -webkit  */
perspective: -webkit-calc(50em + 15px)

The aforementioned code shows a general case when we use prefixed properties and values, for another instance:

transform: rotate(calc(1deg + 1deg));
-webkit-transform: rotate(-webkit-calc(1deg + 1deg));
-ms-transform: rotate(-webkit-calc(1deg + 1deg));
-o-transform: rotate(-webkit-calc(1deg + 1deg));
transform: rotate(-webkit-calc(1deg + 1deg))

So we have at least two possible improvements: (1) put the first line (without prefixes) onto the end and (2) get rid of rules with different vendor prefixes in properties and values. But what is more difficult, there is also complicated combinations between prefixed properties and values in specific cases.

Anyway, thanks for the great tool!

Error

Autoprefixer error: ... "node" ...


Update: I opted fpr prefixfree.js

Watch

It will be useful to have autoprefixer --watch parameter to launch one time and get prefixes after every compilation.
As a workaround I suggest LiveReload, it can launch custom command line string after every compilation.

Error: Cannot find module './lib/rework'

I am running Ubuntu 13.04 and I have installed autoprefixer via sudo npm install --global autoprefixer.

Getting this error:

module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module './lib/rework'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object. (/usr/local/lib/node_modules/autoprefixer/node_modules/rework/index.js:2:18)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:32)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)

Filter prefixer

I think this shouldn't happening.

-webkit-filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fffcde', endColorstr='#00ffffff',GradientType=0 );
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fffcde', endColorstr='#00ffffff',GradientType=0 );

b-vendor-order

* {
  -moz-box-sizing: border-box;
  box-sizing: b-webkit-order-box;
  box-sizing: b-moz-order-box;
  box-sizing: b-ms-order-box;
  box-sizing: border-box
}

{
  -webkit-transition: b-webkit-order linear 0.2s, box-shadow linear 0.2s;
  -moz-transition: b-moz-order linear 0.2s, box-shadow linear 0.2s;
  -ms-transition: b-ms-order linear 0.2s, box-shadow linear 0.2s;
  -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
  -o-transition: border linear 0.2s, box-shadow linear 0.2s;
  transition: border linear 0.2s, box-shadow linear 0.2s
}

what's going on!? your parser doesn't like border or something

Prefixed order in b[order]-box

For example it replaces box-sizing: border-box with box-sizing: b-moz-order-box because of 'order' rule. Actually this may be an rework issue, not sure.

either your data or your filter is incorrect

using rework, i didn't set a filter and i get

{
  -webkit-transition: b-webkit-order linear 0.2s, box-shadow linear 0.2s;
  -moz-transition: b-moz-order linear 0.2s, box-shadow linear 0.2s;
  -ms-transition: b-ms-order linear 0.2s, box-shadow linear 0.2s;
  -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
  -o-transition: border linear 0.2s, box-shadow linear 0.2s;
  transition: border linear 0.2s, box-shadow linear 0.2s

  -moz-box-sizing: border-box;
  box-sizing: b-webkit-order-box;
  box-sizing: b-moz-order-box;
  box-sizing: b-ms-order-box;
  box-sizing: border-box
}

assuming it's last 2 versions by default (when i don't put anything), it's broken: http://caniuse.com/#feat=css-transitions. I should only be seeing -webkit for transitions. i should not see -ms for box-sizing: http://caniuse.com/#search=box-sizing

or maybe the ones that are like b-[vendor]- just shouldn't be there. i think that makes sense.

cli throws on --browser argument

This

autoprefixer test.css -b '2 last versions,ie8'

will make autoprefixer throw:

/Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:155
            throw new Error('Unknown browser `' + name + '`');
                  ^
Error: Unknown browser `2`
    at Object.autoprefixer.check (/Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:155:19)
    at /Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:123:36
    at Array.map (native)
    at Object.autoprefixer.parse (/Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:108:22)
    at Object.autoprefixer.filter (/Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:80:29)
    at Object.autoprefixer.compile (/Users/sindresorhus/Projects/autoprefixer/lib/autoprefixer.js:68:45)
    at Object.<anonymous> (/Users/sindresorhus/Projects/autoprefixer/bin/autoprefixer:126:33)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

test.css

body {
  transition: all 1s ease-out
}

Custom values of prefixed props

I need, for some reasons, following css code:

.class {
    transition: all .1s;
    -o-transition: all .2s;
}

And I want to generate (with autoprefixer help) something like

.class {
    -webkit-transition: all .1s;
    transition: all .1s;
    -o-transition: all .2s;
}

but I got

.class {
    -o-transition: all .2s;
    -o-transition: all .1s;
    -webkit-transition: all .1s;
    transition: all .1s;
}

Is it possible to configure autoprefixer in such a way? i.e. I want the possibility to overwrite prefixed props by myself and place it after unprefixed prop.

Wrong box-sizing prefixing

The box-sizing property...

box-sizing: border-box;

...with default autoprefixer settings converts to:

-moz-box-sizing: border-box;
box-sizing: b-webkit-order-box;
box-sizing: b-moz-order-box;
box-sizing: b-ms-order-box;
box-sizing: border-box

Preserve indentation

A tab or 4 space indentation is converted to 2 spaces:

body {
    transition: all 1s ease-out;
}
body {
  -webkit-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  transition: all 1s ease-out
}

This is important as people don't like tools mucking with their precious indentation.

Source maps

After Autoprefixer's work source maps became broken because it line number is changed.
I suggest a function that will fix source maps (.map files and Sass' custom media-rules).
As a workaround I suggest insertion JS into page that will add prefixes on-the-fly (like -prefix-free.js but with caniuse support) and add prefixes to the original CSS only before publishing to production.

Mechanism doesn't see the second image in multiple gradient

before:

BODY {
  background-image:
    linear-gradient(-45deg, transparent 0, transparent 25px, rgba(204, 54, 54, 0.8) 25px, rgba(204, 54, 54, 0.8) 35px, transparent 35px),
    linear-gradient(-45deg, transparent 0, transparent 25px, rgba(54, 104, 154, 0.8) 25px, rgba(54, 104, 154, 0.8) 35px, transparent 35px);
  background-position: 0 100%, 30px 100%;
  background-size: 60px 100%;
  background-repeat: repeat-x;
}

after:

BODY {
  background-image: -webkit-linear-gradient(-45deg, transparent 0, transparent 25px, rgba(204, 54, 54, 0.8) 25px, rgba(204, 54, 54, 0.8) 35px, transparent 35px),
    linear-gradient(-45deg, transparent 0, transparent 25px, rgba(54, 104, 154, 0.8) 25px, rgba(54, 104, 154, 0.8) 35px, transparent 35px);
  background-image: -o-linear-gradient(-45deg, transparent 0, transparent 25px, rgba(204, 54, 54, 0.8) 25px, rgba(204, 54, 54, 0.8) 35px, transparent 35px),
    linear-gradient(-45deg, transparent 0, transparent 25px, rgba(54, 104, 154, 0.8) 25px, rgba(54, 104, 154, 0.8) 35px, transparent 35px);
  background-image: linear-gradient(-45deg, transparent 0, transparent 25px, rgba(204, 54, 54, 0.8) 25px, rgba(204, 54, 54, 0.8) 35px, transparent 35px),
    linear-gradient(-45deg, transparent 0, transparent 25px, rgba(54, 104, 154, 0.8) 25px, rgba(54, 104, 154, 0.8) 35px, transparent 35px);
  background-position: 0 100%, 30px 100%;
  background-size: 60px 100%;
  background-repeat: repeat-x
}

Incorrect prefixes of values

(v. 0.3.20130423)

Command:

$ autoprefixer test.css -b "ff 15, opera 12, chrome 25"

Output (there is always the the only one prefix):

background: -webkit-linear-gradient(#000, #111); /* -moz for FF 15 and -o for Opera 12? */
background: linear-gradient(#000, #111);
width: -webkit-calc(1px + 1px); /* -moz for FF 15? */
width: calc(1px + 1px)

opacity prefixes

I'm no expert at old IEs, but I noticed that the filter property was missing when selecting IE6+. I think, ideally,

opacity: 0.5;

should turn into:

zoom: 1;                          /* IE 5, 6, 7 need this fix, probably best to only apply if the selector doesn't have zoom already*/ 
filter: alpha(opacity=50);        /* IE 6, 7, 8 */ 
-khtml-opacity: 0.5;              /* Safari 1.x (pre WebKit!) */
opacity: 0.5                      /* IE9+ and all other browsers */

display: flex is not supported.

If I specify display: flex, the expected result, given I specify old browsers, should be something like:

display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;

The actual result is:

display: flex;

Prevent duplication and remove unneeded prefixes

The user might already have some of the properties prefixed while others not. Currently if you run autoprefixer on already prefixed properties it will duplicate them.

Before:

body {
  -webkit-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  transition: all 1s ease-out
}

After:

body {
  -webkit-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  -webkit-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  transition: all 1s ease-out
}

It should also remove no longer needed properties that might already exist in the CSS file.

Standalone JS usage

Can I use Autoprefixer standalone version to use it on developing? Like -prefix-free.js by @LeaVerou.
I tried, but cannot understand what to do with it.
I just downloaded JS and connect it to HTML, then added this lines to main.js:

var css = 'stylesheets/main.css';
var prefixed = autoprefixer.compile(css);

But got Error: Can't parse CSS on line 1393 of autoprefixer.js.

Comments for IE-hack-ish CSS breaks prefixer

Some CSS, mainly legacy stuff, relies on CSS hacks that happen to work. For example, this is for targetting IE5 (or something):

display/**/: block;

Unfortunately it seems AutoprefixerRails.compile can't handle it.

1.9.3p194 :006 > AutoprefixerRails.compile("foo { bar/*broken*/: baz }")
ExecJS::ProgramError: TypeError: Cannot call method 'map' of undefined
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:49:in `rescue in block in call'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:43:in `block in call'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:80:in `block in lock'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2/lib/v8/c/locker.rb:13:in `Locker'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:78:in `lock'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:42:in `call'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/autoprefixer-rails-0.4.20130515/lib/autoprefixer-rails.rb:27:in `compile'
    from (irb):6
    from /Users/adam/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

Support for ::input-placeholder

From "Change an input's HTML5 placeholder color with CSS":

::-webkit-input-placeholder { /* WebKit browsers */
    color:    #999;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color:    #999;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
    color:    #999;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
    color:    #999;
}

I tried different variations (::input-placeholder, ::placeholder) but seems like it doesn't supports by autoprefixer.

Thanks.

Excluding browser prefixes

This is more of a question/feature request.

Is there a way to exclude browsers (and their prefixes)?

Say, to prefix considering the latest two versions of browsers, but leave out Opera prefixes completely.

autoprefixer.compile(css, ['last 2 version', '!opera']);

Awesome tool by the way. Thank you.

(-moz-)document parsing is broken

The following CSS breaks:

@-moz-document url-prefix(){
    .ui-select .ui-btn select{
        opacity:.0001
    }
}

This showed up as part of some jQuery CSS.

This also breaks:

@document url-prefix(){
    .ui-select .ui-btn select{
        opacity:.0001
    }
}

Output in both cases when reading in a file with the above content:

TypeError: 'undefined' is not an object (evaluating 'node.declarations.map')
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:19:in `eval'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:33:in `call'
/Users/adam/.rvm/gems/ruby-1.9.3-p194/gems/autoprefixer-rails-0.4.20130515/lib/autoprefixer-rails.rb:27:in `compile'

Do autoprefixer support gradient?

I have a style like this:

#header{
    position: absolute;
    z-index: 9999;
    height: 40px;
    width: 100%;
    top: -40px;
    overflow: hidden;
    transform: translate(0px, 40px);
    background: gradient(linear,0 0,0 100%,from(#E6E6E6),to(#D1D5D6));
    box-shadow: 0 2px 1px 0 #A3A5A8;
}

but after autoprefixer, css like this:

#header {
  position: absolute;
  z-index: 9999;
  height: 40px;
  width: 100%;
  top: -40px;
  overflow: hidden;
  -webkit-transform: translate(0px, 40px);
  -ms-transform: translate(0px, 40px);
  -o-transform: translate(0px, 40px);
  transform: translate(0px, 40px);
  background: gradient(linear,0 0,0 100%,from(#E6E6E6),to(#D1D5D6));
  box-shadow: 0 2px 1px 0 #A3A5A8;
}

so the background: gradient(linear,0 0,0 100%,from(#E6E6E6),to(#D1D5D6));
is invalid in chrome, I've expected a vendor prefix -webkit would be added, but didn't.

Do the tool support gradient? Or Do I set error?

Best Regards

How should I do to use autoprefixer

Hello:
Some class like this in my project:

.css3vertical {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-box-pack: center;
    -webkit-box-align: center;
}

but the result hasn't any difference to original code.
if my code is like this:

.css3vertical {
    display:box;
    box-orient: vertical;
    box-pack: center;
    box-align: center;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-box-pack: center;
    -webkit-box-align: center;
}

this result is:

.css3vertical {
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: box;
  -webkit-box-direction: normal;
  -webkit-flex-direction: vertical;
  -moz-box-orient: vertical;
  -moz-box-direction: normal;
  -ms-flex-direction: vertical;
  box-orient: vertical;
  -webkit-justify-content: center;
  -moz-box-pack: center;
  -ms-flex-pack: center;
  box-pack: center;
  -webkit-align-items: center;
  -moz-box-align: center;
  -ms-flex-align: center;
  box-align: center;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-box-pack: center;
  -webkit-box-align: center;
}

It's what I want. Must I write like this? Can't autoprefixer handle the first condition?

Latest autoprefixer (0.6.20130721) fails with an exception

Running "autoprefixer:dist" (autoprefixer) task
Warning: Cannot call method 'slice' of undefined Use --force to continue.
TypeError: Cannot call method 'slice' of undefined
    at utils.clone.keyframes (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/keyframes.js:18:30)
    at Array.map (native)
    at Keyframes.clone (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/keyframes.js:16:40)
    at Keyframes.cloneWithPrefix (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/keyframes.js:29:20)
    at /Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/processor.js:16:28
    at Prefixes.each (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/prefixes.js:135:25)
    at /Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/processor.js:15:31
    at CSS.eachKeyframes (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/css.js:21:11)
    at Processor.add (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer/processor.js:11:11)
    at Autoprefixer.rework (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer.js:59:31)
    at Autoprefixer.rework (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer.js:4:61)
    at Autoprefixer.compile (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/node_modules/autoprefixer/lib/autoprefixer.js:52:12)
    at /Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/tasks/autoprefixer.js:42:47
    at Array.forEach (native)
    at Object.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt-autoprefixer/tasks/autoprefixer.js:21:20)
    at Object.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/grunt/task.js:258:15)
    at Object.thisTask.fn (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/grunt/task.js:78:16)
    at Object.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:282:30)
    at Task.runTaskFn (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:235:24)
    at Task.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:281:12)
    at Task.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:215:7)
    at Task.runTaskFn (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:238:9)
    at Task.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:281:12)
    at Task.<anonymous> (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:215:7)
    at null._onTimeout (/Users/leonidkhachaturov/code/hdt/webui/playground/node_modules/grunt/lib/util/task.js:225:33)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

What about a new syntax for gradients?

It would be nice to have a fallback for old syntax when we use the new one (with to keyword). I mean if I type this:

.test {
  background-image: linear-gradient(to right bottom, #000, #fff);
}

I would like to see this output:

.test {
  background-image: -webkit-linear-gradient(top left, #000, #fff); /* and other prefixes... */
  background-image: linear-gradient(top left, #000, #fff); /* fallback to old syntax */
  background-image: linear-gradient(to right bottom, #000, #fff);
}

`-webkit-background-clip:` is removed and `background-clip` isn't prefixified

$ echo 'li { -webkit-background-clip: text; color: black; }' | autoprefixer -b 'chrome 28'
li {
  color: black;
}

$ echo 'li { background-clip: text; color: black; }' | autoprefixer -b 'chrome 28'
li {
  background-clip: text;
  color: black;
}

The problem here is Chrome 28 still requires the -webkit- prefix.

In fact, I can’t seem to get the -webkit prefix no matter what version of Chrome I specify. The only way I could get the prefix is to run it: autoprefix -b '> 1%':

echo 'li { background-clip: text; color: black; }' | autoprefixer -b "> 1%"
li {
  -webkit-background-clip: text;
  background-clip: text;
  color: black;
}

Support "appearance"?

I see that appearance is not supported equally through different browsers, but maybe at least some

appearance: none
-webkit-appearance: none
-moz-appearance: none

support would be nice?

Property 'undefined' of object #<Compiler> is not a function

In Rails gem with 0.4.20130524 version:

ExecJS::ProgramError - TypeError: Property 'undefined' of object #<Compiler> is not a function=0A

Maybe part of new unreleased (in npm) fixes for Rework? In my case, I can't reproduce issue. Will be good, if somebody help my with CSS, that call this error.

Support for border-image (and sub-properties)

http://caniuse.com/#search=border-image etc.

However, there should be at least one hack for it: when you add a fill value for unprefixed border-images, you should remove it from all the prefixed ones, so

border-image: url('frame.png') 20% fill stretch stretch;

should become

-webkit-border-image: url('frame.png') 20% stretch stretch;
   -moz-border-image: url('frame.png') 20% stretch stretch;
     -o-border-image: url('frame.png') 20% stretch stretch;
        border-image: url('frame.png') 20% fill stretch stretch;  

(and don't forget to support gradients inside of border-images)

Include additional browser choices in updater coffeescript file

Currently the update script updaters/lib/updater.coffee generates data for Firefox, Chrome, Safari, iOS, Opera, and IE. For mobile development work, it would help to also have supported android and bb identifiers added to the browsers: object.

  # Can I Use browser names to internal
  browsers:
    firefox: 'ff'
    chrome:  'chrome'
    safari:  'safari'
    ios_saf: 'ios'
    opera:   'opera'
    ie:      'ie'
    android: 'android'
    bb:      'bb'

Add a way to add basic support for stuff that don't yet exist at caniuse

You should add support for #44 and similar stuff, like hyphens, tab-size etc, before they appear at CanIuse.

It is better to have those properties always prefixed, than to wait it to be added properly. And when it would be at canIuse, you would update you data with it, and noone would be hurt.

But right now I need either to use my own mixins in preprocessors, or to write all the stuff manually, while it would be much better to have working solution from autoprefixer now and optimized one later.

Proposed improvements for flex fallbacks

After reading different articles on the topic, I've begun to summarize the ways to fallback the flex spec.

screen shot 2013-05-16 at 10 47 17 pm

I will make a PR that implements as much as I can.

Of particular difficulty is flex-grow flex-shrink and flex-basis. To have these fallback we need to assign the flex shorthand for -ms- but that seems dubious since we cannot assume the three individual properties are all coming from one selector. It also appears impossible to support shrink and basis in the 2009 spec. In short it doesn't seem like there is a way to provide fallback for the grow/shrink/basis properties.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.