【发布时间】:2017-08-11 13:57:50
【问题描述】:
我想复制一个文件夹并使用 grunt 重命名该文件夹的文件。
基本结构:
mainfolder
-project
-project.js
-project.html
我想复制项目文件夹并想用newname 替换project,所以它看起来像:
mainfolder
-project
-project.js
-project.html
-newname
-newname.js
-newname.html
我发现重命名文件名很困难(内容被替换为新名称)。 我已按照以下步骤操作:
- 将项目文件夹复制到 newname1 文件夹
- 替换了 newname 文件夹中的内容
- 已删除 newname1 文件夹
我尝试合并所有操作,但没有成功。
module.exports = function(grunt) {
grunt.initConfig({
copy: {
main: {
expand: true,
src: 'project/**',
dest: 'newname1',
},
},
replace: {
example: {
src: ['newname1/*'],
dest: 'newname',
replacements: [{
from: 'project',
to: 'newname'
},
{
from: 'Project',
to: 'Newname'
}
],
}
},
clean: {
folder: ['newname1']
},
rename: {
main: {
files: [{
src: ['newname/**]'],
dest: 'newname/**]'
}, ]
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['copy', 'replace', 'clean']);
};
【问题讨论】:
标签: angularjs gruntjs grunt-contrib-copy