sassgruntjsgrunt-contrib-watchgrunt-contrib-sass

Change 'dest' option dynamically


Hi all,

Following this question : https://github.com/gruntjs/grunt-contrib-sass/issues/190

I'm trying to specify the 'dest' option depending on the 'src' one. The only difference is the /scss that has to be removed.

Here is a sample of my current code :

    sass: {
      dist: {
        options: {
          style: 'expanded',
          sourcemap: 'none',
          trace: true,
        },
        files: {
          './css/laptop.css': './scss/css/laptop.scss',
         ....
         ... (160 more lines)
         ....
          './css/player.css': './scss/css/player.scss'
        }
      }
    },

I tried

    files: [{
      expand: true,
      src: ['**/*.scss'],
      dest: function(path) { return path.replace(/(\/scss)/,"") },
      ext: '.css'
    }]

But apparently Warning: Arguments to path.join must be strings Use --force to continue.

Thanks!


Solution

  • After some research I discovered grunt-newer which can be used this way:

      css:{
        files: [
          './scss/**'
        ],
        tasks: ['newer:sass'],
        livereload: {
          options: { livereload: true },
          files: ['./**'],
        },
      }
    

    It's not what I was trying to do exactly but It optimised perfectly the grunt process. Really nice plugin!!