grunt-init-copy分组子任务
我正在尝试使用grunt copy来完成两个单独的任务。 我不需要同时运行两套,所以我试图把它们分开。 我想复制所有的字体,或复制所有的全局图像。 我正在为Windows的networking应用程序工作,每个页面都是自己的网站,所有它自己的JS,CSS等。
- 将所有全局图像复制到构build文件夹中
- 将所有全局字体复制到生成文件夹
文件夹结构
~ Project |-- app | |-- fonts | |-- images | | |-- global | |-- php, styles, js, etc |-- build | |-- page1 | | |-- fonts | | |-- images | | | |-- global | | |-- html, css, js, etc
我曾经希望设置一个grunt copy:images
和grunt copy:fonts
任务,但到目前为止,它不是我所希望的。
这是我的Gruntfile.js
一个简单的例子
module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), copy: { images: { // copy the global image folder into each build directory images1: { expand: true, src: 'app/img/global/**/*', dest: 'build/projectname-1.1-intro/img/global/', flatten: true, filter: 'isFile', }, // ... there are about 30 more pages in the build to add images to }, fonts: { // copy the app/fonts folder into each build directory fonts_one: { expand: true, src: 'app/fonts/**/*', dest: 'build/projectname-1.1-intro/fonts/', flatten: true, filter: 'isFile', }, // ... there are about 30 more pages in the build to add fonts to }, }, // copy }); // initConfig grunt.loadNpmTasks('grunt-contrib-copy'); grunt.registerTask('default',['watch']); } // module.exports
而当grunt copy:images
或grunt copy:fonts
运行,它返回:
Running "copy:images" (copy) task
但实际上并没有复制任何东西
我能够做到这一点的唯一方法就是将所有的子子任务合并到任务中,如下所示:
module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), copy: { // copy the global image folder into each build directory images1: { expand: true, src: 'app/img/global/**/*', dest: 'build/projectname-1.1-intro/img/global/', flatten: true, filter: 'isFile', }, // ... there are about 30 more pages in the build to add images to // copy the app/fonts folder into each build directory fonts_one: { expand: true, src: 'app/fonts/**/*', dest: 'build/projectname-1.1-intro/fonts/', flatten: true, filter: 'isFile', }, // ... there are about 30 more pages in the build to add fonts to }, // copy }); // initConfig grunt.loadNpmTasks('grunt-contrib-copy'); grunt.registerTask('default',['watch']); } // module.exports
然后返回:
Running "copy:images1" (copy) task Copied 34 files Running "copy:fonts_hall1" (copy) task Copied 34 files
我看着multitask
,但现在我觉得我失去了明显的东西。