Autoprefixing using Grunt + PostCSS

2.8k views Asked by At

I'm using Sass and rather than create a mixin I'm trying to use grunt-postcss to add my vendor prefixes on my class definitions...

this is my css

@keyframes {
    from { transform:scale(1); }
      to { transform:scale(2); }
}

My gruntfile

watch:{
        sass: {
            files: ["sass/partials/*.scss","sass/*.scss"],
            tasks:['sass','postcss']
        }
    },
    sass :{
        dev: {
            files: {
                "web/css/styles.css" :  "sass/demo.scss"
            }
        }
    },
    postcss :{
        options: {
            processors:[
                require('autoprefixer-core')({browsers:'>5%'})
            ]
        },
        dist: {
            src: 'web/css/*.css'
        }
    },

But the final file doesn't have the prefixes. What am i doing wrong?

[UPDATE]

i tried changing the

dist: {
   src:
}

to

dist : { files: {}}

but still didn't work is this a bug? i note that no one has tried to use the @keyframes definitions before

[UPDATE]

while running the task postcss:dist I am getting and error

Fatal Error: undefined is not a function

Am i missing something here?

3

There are 3 answers

0
srlm On

I think your Grunt file notation is incorrect. Try this:

dist: {
            files: [{
                expand: true,
                cwd: 'web/css/',
                src: ['**/*.css'],
                dest: 'web/css/'
            }]
        }
1
wenom64 On

You don't have a name of animation

@keyframes zoom{
    from { transform:scale(1); }
      to { transform:scale(2); }
}
0
smallhours On

The following worked for me:

grunt.initConfig({

  sass: {
    dist: {
      files: {
          'assets/css/style.css': 'assets/sass/style.scss'
      }
    }
  },

  postcss: {
    options: {
      map: true,
      processors: [
        require('autoprefixer')({
          browsers: ['last 2 versions']
        })
      ]
    },
    dist: {
      src: 'assets/css/style.css'
    }
  },

  watch: {
    styles: {
      files: ['assets/sass/*.scss', 'assets/sass/common/*.scss'],
      tasks: ['sass','postcss']
    }
  }

});

grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['sass', 'watch']);
grunt.registerTask('default', ['sass', 'postcss']);