我想在目录及其子目录中的所有文件中使用grunt-string-replace替换字符串
例如,在所有这些文件中:
dist/templates_and_modules/templates/template1/template1.php
dist/templates_and_modules/templates/template2/template2.php
dist/templates_and_modules/modules/module1.php
dist/templates_and_modules/modules/module1.php
Run Code Online (Sandbox Code Playgroud)
我想替换
/*remove->*/
Run Code Online (Sandbox Code Playgroud)
有:
/*
Run Code Online (Sandbox Code Playgroud)
和
/*<-remove*/
Run Code Online (Sandbox Code Playgroud)
同
*/
Run Code Online (Sandbox Code Playgroud)
使用明确定义的文件,它可以:
strrep: {
dist: {
files: {
'<%= yeoman.dist %>/templates_and_modules/templates/template1/template1.php':
'<%= yeoman.dist %>/templates_and_modules/templates/template1/template1.php'
},
options: {
replacements: [
{
pattern: '/*remove->*/',
replacement: '/*'
},
{
pattern: '/*<-remove*/',
replacement: '*/'
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不能让它与目录中的所有文件一起使用.
您应该能够使用通配模式来定义它处理的文件和文件夹.
像这样的东西:
src: [ '<%= yeoman.app %>/templates_and_modules/**/*.php' ]
dest: '<%= yeoman.dist %>/templates_and_modules/'
Run Code Online (Sandbox Code Playgroud)
但是,该插件似乎旨在将文件复制到新目标,而不是像您尝试那样就地修改它们.这是一个将它们复制到新位置的完整示例:
module.exports = function(grunt) {
grunt.initConfig({
'string-replace': {
dist: {
src: './app/mylibs/**/*.js',
dest: './dist/mylibs/',
options: {
replacements: [{
pattern: 'old',
replacement: 'new'
}]
}
}
}
});
grunt.loadNpmTasks('grunt-string-replace');
grunt.registerTask('default', ['string-replace']);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8965 次 |
| 最近记录: |