Search code examples
gruntjsgrunt-contrib-uglify

Grunt uglify not finding files


I have the following directory structure:

--development 
  -js
    -pages

--js
  -pages

I'm trying to take all files in development/js/pages and output them js/pages and minify them using grunt uglify but still keep seperate files - I don't want to combine all the files together. I've tried the following:

build: {
            src: 'development/js/pages/*.js',
            dest: 'js/page',
            options: {
                sourceMap: true,
                compress: true,
                mangle: true
            }
        } 

but this gives me an error: unable to write js/page file

Then I tried this, which is on the uglify documentation:

build : {
            files: [{
                cwd: 'development/js/pages',
                src: '*.js',
                dest: 'js/page'
            }],
            options : {
                sourceMap: true,
                compress: true,
                mangle: true

            }
}

but this just gives me this error for each file in development/js/pages:

source File "filename.js" not found

and then another error saying Destination (js/page) not written because the source files are empty.

Any ideas why?


Solution

  • For anyone else looking the second option above almost worked but I needed to remove the options block and include expand in the files block:

    pages: {
                files: [{
                    expand: true,
                    cwd: 'development/js/page',
                    src: '*.js',
                    dest: 'js/page/',
                    ext : '.min.js',
                }]
                }