Grunt uglify not finding files

懵懂的女人 提交于 2019-12-20 02:32:30

问题


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?


回答1:


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',
            }]
            }



回答2:


I wanted to answer with another option.

Here is how I write my Uglify Grunt task incase you want to keep your options. It's setup to read as (dest : src), I also concat all my library files in task prior to Uglify.

-

uglify: {
        options: {
            // the banner is inserted at the top of the output
            banner: '/* \n Site: <%= pkg.name %> \n Version: <%= pkg.version %> \n Build Date: <%= grunt.template.today("mm-dd-yyyy") %> \n */\n \n'
        },
        site: {
            files: {
                './_build/js/lib/lib.min.js': ['<%= concat.site.dest %>'],
                './_build/js/app/app.min.js': ['./_build/js/app/app.js']
            }
        }
    },


来源:https://stackoverflow.com/questions/22839766/grunt-uglify-not-finding-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!