How to compile dynamically sass files from directory with grunt sass?

by AlDunchev   Last Updated April 15, 2019 11:07 AM - source

I am trying to compile all .scss files in sass to css and not specify the exact names. I know how to do it from the command line (node_modules/node-sass/bin/node-sass sass --o cssc), but I have to use Grunt with node sass in a project.

Here is my Grunt.js file:

const sass = require('node-sass');

module.exports = function(grunt) {

  grunt.initConfig({

    // jshint.
    jshint: {
      files: [
        'Gruntfile.js',
        'js/**/*.js',
      ],
      options: {
        globals: {
          jQuery: true,
        }
      },
    },

    // sass.
    sass: {
      options: {
        sourceMap: true,
        implementation: sass
      },
      dist: {
        files: {
          'css/**/base.css': 'sass/**/*.scss', // This is not working.
        }
      }
    },

    // watch.
    watch: {
      set1: {
        files: 'sass/**/*.scss',
        tasks: ['sass'],
      },
      set2: {
        files: ['sass/**/*.scss'],
        tasks: ['sasslint'],
      },
    },

    autoprefixer: {
      options: {
         browsers: ['last 2 versions', 'ie 9', 'ie 10']
      },
      no_dest_single: {
        src: 'css/styles.css'
      },
    },

    // notify.
    notify_hooks: {
      options: {
        title: "Grunt",
        enabled: true,
        success: true,
        duration: 2,
      }
    },

    // Sasslint.
    sasslint: {
      options: {
          configFile: '.sass-lint.yml',
      },
      target: ['sass/**/*.scss']
    },
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-notify');
  grunt.loadNpmTasks('grunt-sass-lint');
  grunt.loadNpmTasks('grunt-autoprefixer');

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

  grunt.task.run('notify_hooks');

};

I could not find an example of the syntax.

Thanks in advance!



Related Questions


Nodejs does not work in https

Updated March 01, 2018 20:07 PM

How to install Node.js on Drupal 8?

Updated February 20, 2018 23:07 PM


How to install Node.JS on Drupal?

Updated February 22, 2018 20:07 PM

How to install "drupal-nodejs" and "forever"?

Updated February 24, 2018 03:07 AM