javascriptgruntjsgrunt-contrib-uglifygrunt-contrib-cssmin

Getting interesting error when compressing the JS files - trying to read a folder as JS file


I have a Grunt task that loops through directories and sub directories and compresses the JS and CSS files.

I get the following error which means that it accidentally thought less.js folder is a JavaScript file. I am wondering is it possible to configure that regular expression (wildcard) to skip directories that have name such as less.js.

enter image description here

module.exports = function(grunt) {
    grunt.initConfig({
        uglify: {
            options: {
                mangle: false
            },
            files: {
                expand: true,
                flatten: false,
                cwd: "script",
                src: ["**/*.js", "**/!*.min.js"],
                dest: "release/script",
                ext: ".js"
            }
        }, cssmin: {
            target: {
                files: [{
                    expand: true,
                    flatten: false,
                    cwd: "style",
                    src: ["**/*.css", "**/!*.min.css"],
                    dest: "release/style",
                    ext: ".css"
                }]
            }
        }
    });

    grunt.loadNpmTasks("grunt-contrib-cssmin");
    grunt.loadNpmTasks("grunt-contrib-uglify");

    grunt.registerTask("default", ["uglify", "cssmin"]);
};

Solution

  • You could decide to ignore any folder that contains .js in the folder name by adding this rule to your files:

    !*.js/