Gruntjs Grunt:在生成时更改文件扩展名
我想写一个Grunt任务,在构建过程中,它将复制我所有的.html文件,并在/dist中生成一个.asp版本 我一直在尝试用它来实现这一点,以下是我所拥有的:Gruntjs Grunt:在生成时更改文件扩展名,gruntjs,grunt-contrib-copy,Gruntjs,Grunt Contrib Copy,我想写一个Grunt任务,在构建过程中,它将复制我所有的.html文件,并在/dist中生成一个.asp版本 我一直在尝试用它来实现这一点,以下是我所拥有的: copy: { //some other tasks that work... //copy an .asp version of all .html files asp: { files: [{ expand: true, dot: true, cwd: '<%= conf
copy: {
//some other tasks that work...
//copy an .asp version of all .html files
asp: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
src: ['{,*/}*.html'],
dest: '<%= config.dist %>',
option: {
process: function (content, srcpath) {
return srcpath.replace(".asp");
}
}
}]
} //end asp task
},
复制:{
//其他一些有效的任务。。。
//复制所有.html文件的.asp版本
asp:{
档案:[{
是的,
多特:没错,
cwd:“”,
src:['{,*/}*.html'],
目标:'',
选项:{
进程:函数(内容、路径){
返回srcpath.replace(“.asp”);
}
}
}]
}//结束asp任务
},
我知道
过程
功能实际上并不正确。。。我试过几种不同的正则表达式,但都没用。当我运行asp
任务时,Grunt CLI会说我的it复制了2个文件,但是找不到它们。非常感谢您的帮助。您可以使用重命名
功能来完成此操作
例如:
copy: {
//some other tasks that work...
//copy an .asp version of all .html files
asp: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
src: ['{,*/}*.html'],
dest: '<%= config.dist %>',
rename: function(dest, src) {
return dest + src.replace(/\.html$/, ".asp");
}
}]
} //end asp task
},
复制:{
//其他一些有效的任务。。。
//复制所有.html文件的.asp版本
asp:{
档案:[{
是的,
多特:没错,
cwd:“”,
src:['{,*/}*.html'],
目标:'',
重命名:函数(dest,src){
返回dest+src.replace(/\.html$/,“.asp”);
}
}]
}//结束asp任务
},
这应该是可行的。您可以使用
重命名
功能来实现
例如:
copy: {
//some other tasks that work...
//copy an .asp version of all .html files
asp: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
src: ['{,*/}*.html'],
dest: '<%= config.dist %>',
rename: function(dest, src) {
return dest + src.replace(/\.html$/, ".asp");
}
}]
} //end asp task
},
复制:{
//其他一些有效的任务。。。
//复制所有.html文件的.asp版本
asp:{
档案:[{
是的,
多特:没错,
cwd:“”,
src:['{,*/}*.html'],
目标:'',
重命名:函数(dest,src){
返回dest+src.replace(/\.html$/,“.asp”);
}
}]
}//结束asp任务
},
这应该是可行的。实际上,
重命名
方法是可行的,不过通过仔细查看Grunt文档,我发现您也可以使用ext
属性来完成一个简单的文件扩展名更改,如:ext:'.asp'
。注意,您可能希望使用path.sep()
,加入dest和src参数,因为现在您加入文件和文件夹时没有斜杠somefoldersomefile.asp
,而不是somefolder/somefile.asp
。实际上,重命名
方法是有效的,不过通过仔细查看Grunt文档,我发现您还可以使用ext
属性完成简单的文件扩展名更改,如:ext:'.asp'
。请注意,您可能希望使用path.sep()
,加入dest和src参数,因为现在您加入文件和文件夹时没有斜杠somefoldersomefile.asp
,而不是somefolder/somefile.asp
。