0

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'
      ]);
assistbss
  • 527
  • 7
  • 25

1 Answers1

1

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'
               }        
     },
Andrew
  • 769
  • 7
  • 16
  • Relative path to css/foo.css is css/foo.css. Gruntfile is in the same path of css folder. If I set cwd to css and src to foo.css, I get however 'No files created'. What am I missing? – assistbss Feb 11 '16 at 16:56
  • You don't need the "target" inside foo or bar, have updated my answer. – Andrew Feb 12 '16 at 09:18
  • Thanks. I'm really near to achieve what i need. The minified file is production/productionmy/bar.min.css, but I would like that it becomes production/productionmy.min.js. Any way to ovverride file name and not just destination folder? – assistbss Feb 12 '16 at 09:46
  • There is a different syntax you can use that will do that, have updated answer. – Andrew Feb 12 '16 at 10:00