热门搜索 :
考研考公
您的当前位置:首页正文

Automatically in grunt(concat &a

来源:东饰资讯网
//Code example 13-watch
module.exports = function(grunt) {
// Load the plugins that provide the "concat" and "watch" tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
// Project configuration.
[ 70 ]Chapter 3
grunt.initConfig({
srcFiles: ["src/a.js", "src/b.js", "src/c.js"],
concat: {
target1: {
files: {
"build/abc.js": "<%= srcFiles %>"
}
}
},
watch: {
target1: {
files: "<%= srcFiles %>",
tasks: ["concat"]
}
}
});
// Define the default task
grunt.registerTask('default', ['concat', 'watch']);
};
grunt
Running "concat:target1" (concat) task
File "build/abc.js" created.
Running "watch" task
Waiting...

At this point, our watch task is running and is Waiting... for one of our files to
change; so if we modify and save src/b.js , we should see the following appended
to our output:

OK
>> File "src/b.js" changed.
Running "concat:target1" (concat) task
[ 71 ]Using Grunt
File "build/abc.js" created.
Done, without errors.
Completed in 0.648s at Tue Sep 17 2013 21:57:52 GMT+1000 (EST)
Waiting...

Our concat task was run, and our watch task is Waiting... again, ready for more
changes. Since we are watching our source files, we can now minimize our terminal
window and continue with our development workflow, knowing that Grunt is
running in the background, taking care of the "grunt" work for us.

Top