简体   繁体   中英

Concat and Uglify JS Files from Two Different Sources using Grunt

I have different sets of JS files that I want to concat and uglify. One is for the app, one is for the website. My gruntfile.js looks something like the one below. The problem is that only the website one runs even though I have registered the grunt task as: grunt.registerTask('default', ['concat:app', 'concat:website', 'uglify']);

concat: {
    app: {
        js: {
            src: [
            'app/js/vendor/jquery.js',
            'app/js/app/ui.js',
            'app/js/app/data.js'
        ],
            dest: 'app/js/app.js'
        },
        css: {
            src: [
            'app/css/vendor/normalize.css',
            'app/css/vendor/ui.css',
            'app/css/vendor/style.css',
        ],
            dest: 'app/css/app.css'
        }
    },
    website: {
        src: [
            'app/js/vendor/jquery.js',
            'app/js/website/scripts.js'
        ],
        dest: 'app/js/common.js'
    }
},
uglify: {
    development: {
        options: {
            preserveComments: false
        },
        files: {
            'app/js/app.min.js': 'app/js/app.js',
            'app/js/common.min.js': 'app/js/common.js'
        }
    }
}

concat can concatenate multiple files and types in the same target, but you have to use the proper grunt syntax ( https://www.npmjs.com/package/grunt-contrib-concat#multiple-files-per-target ):

concat: {
  app: {
    'app/js/app.js': [
        'app/js/vendor/jquery.js',
        'app/js/app/ui.js',
        'app/js/app/data.js'
    ],
    'app/css/app.css': [
        'app/css/vendor/normalize.css',
        'app/css/vendor/ui.css',
        'app/css/vendor/style.css',
    ],
  }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM