0

I have the following gruntfile.js:

module.exports = function(grunt) {
  require('jit-grunt')(grunt);

  grunt.initConfig({
    uglify: {
      options: {
        manage: false
      },
      my_target: {
        files: [{
          expand: true,
          cwd: 'assets/js',
          src: '*.js',
          dest: 'assets/js/min' 
        }]
      },
    },
    less: {
      development: {
        options: {
          compress: true,
          yuicompress: true,
          optimization: 2
        },
        files: [
        {
          expand: true, // Recursive
          cwd: "assets", // The startup directory
          src: ["**/*.less"], // Source files
          dest: "assets/", // Destination
          ext: ".css" // File extension 
        }
      ]
      }
    },
    watch: {
      styles: {
        files: ['assets/**/*.less', 'assets/js/*.js'], // which files to watch
        tasks: ['less', 'newer:uglify'],
        options: {
          nospawn: true
        }
      }

    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-newer');
  grunt.registerTask('default', ['less', 'watch', 'newer:uglify']);
};

And the following path distribution:

| assets
|-- folder-1
    |-- less
|-- folder-2
    |-- less

With the current gruntfile.js, my output is a sub-level of the less folder:

| assets
|-- folder-1
    |-- less
       |-- css
|-- folder-2
    |-- less
       |-- css

But it should be on the same level of the LESS file. For example:

| assets
|-- folder-1
    |-- less
    |-- css
|-- folder-2
    |-- less
    |-- css

Any idea on how to modify my gruntfile.js? Is that possible?

1 Answer 1

2

If I understand your correctly, you want a css/ folder as a sibling of a less/ folder in each of your folder-{x}/ folders.

This can be done by adding the rename property to your less task config:

files: [
    {
        expand: true, // Recursive
        cwd: "assets", // The startup directory
        src: ["**/*.less"], // Source files
        dest: "assets/", // Destination
        ext: ".css", // File extension
        rename: function (dest, src) {
            return (dest + src.replace('less/', 'css/'));
        }
    }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.