问题描述:

I have a Grunt files as follows,

module.exports = function(grunt) {

grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),

'uglify': {

options: {

preserveComments: 'some',

},

my_target: {

files: {

'site/assets/js/js_code.js': [

/* Libs */

'/js/libs/jquery_2.2.4.min.js',

'/js/libs/underscore_1.8.3.min.js',

'/js/libs/backbone_1.3.3.min.js',

/* Plugins */

'/js/plugins/dropzone.min.js',

'/js/plugins/jquery.magnific-popup.min.js',

'/js/plugins/jquery.validate.min.js',

/* Build JS Functions */

'/js/functions.js',

'/js/builder.js',

]

}

}

},

'sass': {

dist: {

options: {

style: 'expanded',

compass: true,

},

files: {

'assets/css/styles.css': '/scss/styles.scss',

} //End of Files

} //End of Dist.

}, //End of SASS

watch: {

'JS': {

files: ['/js/*.js'],

tasks: ['uglify'],

options: { spawn: false },

},

'Scss': {

files: ['/scss/*.scss'],

tasks: ['sass'],

options: { spawn: false },

}

}

});

grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.loadNpmTasks('grunt-contrib-sass');

grunt.loadNpmTasks('grunt-contrib-watch');

};

What I can not work out, and I have done lots of research but cant seems to find an answer, is how to set up uglify to have more than one task.

I know I can set up more than one file target but I dont want my watch to running these. So I want to be setup a 'libs.js', 'plugins.js' and something like 'my_code.js'. But I don't want the libs and plugins to be run each time my code is edited/updated. But what to be able to set it up in a way so that I can run something like, grunt uglify-libs.

Is that doable?

Many thanks

UPDATE

As per comments below, I try to explain in more detail.

Right now, I run grunt watch Which returns one output file.

I want to change this to have three output files, one for the libs files, one for the plugins and the other would be the code I write.

So when I run Grunt watch, that would only watch the files in my code but not any of the libs or plugins files.

Then I want to be able to run, Grunt uglify-libs, this would then make the libs file.

Same goes for the plugins, but something like, Grunt uglify-plugs.

So basically I want three uplify tasks but only one of them is run within the watch function.

Hope that help explain more.

Many thanks.

网友答案:

If i understood you right, you want to use one grunt-command to start multiple tasks. You can do this by creating a "parent" tasks, who calls multiple sub-tasks like this:

  grunt.registerTask('uglify-libs', ['sass', 'uglify']);
相关阅读:
Top