下面是一个类,我只想从这个类中替换特定的行。
class abc{
Rest of code...
Titan.include('`MyFunction/myControl`.js');
Rest of code...
}我希望将Titan.include替换为myfunc,并从行中删除".js“一词:
myfunc('`MyFunction/myControl`');我正在使用grunt.loadNpmTasks('grunt-string-replace');
任何帮助都是非常感谢的。
发布于 2014-12-20 02:19:52
如果您使用咕噜-文本-替换插件,您可以按以下方式配置它:
replace: {
myReplace: {
src: [ 'yourFile' ], //your file
dest: 'destinationFile', //path and namefile where you will save the changes.
replacements: [ {
from: /Titan\.include\('(.*)\.js'\);/g, //Regexp to match what you need
to: "myfunc('$1');" //Replacement for the Regexp
} ]
}
}无论如何,我从来没有使用过咕噜-字符串-替换插件,但如果你需要用它代替咕噜-文本-替换我的东西应该这样工作:
'string-replace': {
dist: {
files: {
'dest/': 'yourfile' //Key: path where you will save the changes. Value: File or path where you will search.
},
options: {
replacements: [{
pattern: /Titan\.include\('(.*)\.js'\);/g,
replacement: "myfunc('$1');"
}]
}
}https://stackoverflow.com/questions/27563046
复制相似问题