我正在尝试使用grunt副本执行两项单独的任务。我不需要同时运行两个集合,所以我试图将它们分开。我想复制所有字体,或复制所有全局图像。我正在开发一个适用于Windows的Web应用程序,每个页面最终都是它自己的网站,包含所有自己的js,css等。
文件夹结构
~ 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
,但现在我觉得我错过了一些明显的东西。