gruntjsgrunt-contrib-cssmin

grunt-contrib-cssmin No files created


I'm unable to properly configure cssmin. In this specific case I'm trying to confiure cssmin in order to create 2 different css minified file starting from two different css file. Using grunt --verbose on terminal I get:

Running "cssmin:foo" (cssmin) task
Verifying property cssmin.foo exists in config...OK
File: [no files]
>> No files created.

Running "cssmin:bar" (cssmin) task
Verifying property cssmin.bar exists in config...OK
File: [no files]
>> No files created

Here is the tree of the files:

  1. /Gruntfile.js
  2. /css/foo.css
  3. /css/bar.css
  4. /production/

Here is the configuration in Gruntfile.js

var config = {};    

config.cssmin = {
      foo: {
        target: {
          files: [{
            expand: true,
            cwd: 'production/productionext',
            src: 'css/foo.css',
            dest: 'production/productionext',
            ext: '.min.css'
          }]
        }
      },
      bar: {
        target: {
          files: [{
            expand: true,
            cwd: 'production/productionmy',
            src: 'css/bar.css',
            dest: 'production/productionmy',
            ext: '.min.css'
          }]
        }
      };

  grunt.initConfig(config);

  grunt.loadNpmTasks('grunt-contrib-cssmin');


    grunt.registerTask('default', [
        'cssmin:foo',
        'cssmin:bar'
      ]);

Solution

  • The cwd property sets a current working directory which your src path will then be relative to. In your example it will be looking for your first source file at 'production/productionmy/css/foo.css'.

    Also you don't need the "target" bit inside foo and bar, foo and bar are the targets, so it should look like this:

    foo: {        
         files: [{
                    expand: true,
                    cwd: 'css',
                    src: 'foo.css',
                    dest: 'production/productionext',
                    ext: '.min.css'
                }]        
          },
    bar: {        
         files: [{
                    expand: true,
                    cwd: 'css',
                    src: 'bar.css',
                    dest: 'production/productionmy',
                    ext: '.min.css'
                }]        
          }  
    

    If you want to rename the file as part of the minification process use the following syntax:

    foo: {        
            files: {                   
                    'production/productionext/someothername.min.css': 'css/foo.css'
                   }        
         },