jonschlinkert/grunt-refactor

Gruntfile setup example

Opened this issue · 2 comments

any example to show how to set up grunt-refactor in Grunt Init instead of for grunt-rename and grunt-string-replace task?

+1

Mipme commented

This one is based on the Gruntfile.js in the grunt-refactor directory and my grunt capabilities are rather basic - but it works for my needs:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    // Regex for refactor task.
    replacements: require('./node_modules/grunt-refactor/replacements').init(grunt),

    refactor: {
      // replace.sass_to_less
      sass_to_less: {
        options: {
          replacements: '<%= replacements.regex.sass %>'
        },
        files: [{
            expand: true,
            flatten: true,
            cwd: 'scss/',
            src: ['**/*.scss'],
            dest: 'less/',
            ext: '.less',
          }
        ]
      },
    },

    // Strip preceding underscores from '.scss'
    // filenames since LESS doesn't require them.
    rename: {
      remove_underscores: {
        options: {
          from: /\_/,
          to: ''
        },
        src: 'less/**/*.less'
      }
    },

  });

  // Load this task.
  grunt.loadTasks('node_modules/grunt-refactor/tasks');

  // Refactor code.
  grunt.registerTask('sass', ['refactor:sass_to_less']);

  // The default task to be run with the 'grunt' command.
  grunt.registerTask('default', ['sass', 'rename']);
};

This task does nothing more than taking all .scss files from directory scss/ and transcompiling it into the less/ directory.