Grunt Autoprefixer Plugin

3.0.4 · deprecated · verified Wed Apr 22

grunt-autoprefixer is a Grunt.js plugin designed to automatically add vendor prefixes to CSS properties using data from the Can I Use database, leveraging the underlying Autoprefixer library (a PostCSS plugin). It simplifies cross-browser compatibility by ensuring CSS rules are correctly prefixed for target browsers without manual intervention. The package is currently at version 3.0.4 and is explicitly marked as deprecated by its maintainers, who recommend transitioning to `grunt-postcss` for future projects and maintenance. `grunt-postcss` provides a more flexible and modern PostCSS-based build pipeline, allowing for `autoprefixer` to be used as one of many PostCSS plugins within the Grunt environment. Its release cadence is effectively halted due to its deprecated status, with no new major versions expected.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `grunt-autoprefixer`, integrate it into a `Gruntfile.js`, and configure a basic task to process CSS files from `src/css` and output them to `dist/css` with vendor prefixes applied according to specified browser targets.

// Gruntfile.js
module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    autoprefixer: {
      options: {
        // Specify browsers to target. This can also be done via a .browserslistrc file.
        browsers: ['last 2 versions', 'ie >= 9', 'safari >= 7'],
        cascade: true, // Maintain visual cascade for readability
        remove: true // Remove outdated prefixes
      },
      dist: {
        files: [{
          expand: true,
          cwd: 'src/css/',
          src: '{,*/}*.css',
          dest: 'dist/css/'
        }]
      }
    }
  });

  // Load the plugin that provides the "autoprefixer" task.
  grunt.loadNpmTasks('grunt-autoprefixer');

  // Register a default task.
  grunt.registerTask('default', ['autoprefixer']);

  // To run:
  // 1. npm install grunt grunt-autoprefixer --save-dev
  // 2. Create src/css/style.css with some unprefixed CSS like `display: flex;`
  // 3. Run `npx grunt` in your terminal.
  // 4. Check dist/css/style.css for prefixed output.
};

view raw JSON →