您好,欢迎来到知库网。
搜索
您的当前位置:首页Automatically in grunt(concat &a

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.

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务