我的 gruntfile 中有以下代码:
'string-replace': {
inline: {
files: {
'entity/templates/': 'entity/templates/*',
},
options: {
replacements: [{
pattern: /Article/g,
replacement: '<%= entityName %>'
}, {
pattern: /article/g,
replacement: '<%= _.slugify(entityName) %>'
}]
}
}
}
我正在尝试用表达式替换几个文件中的“文章”一词。我希望这个表达式在被替换的文件中如此打印,但现在它被评估了。
如何转义代码?
我正在使用 https://github.com/erickrdch/grunt-string-replace但我认为问题在于 grunt 如何评估表达式,对吗?
错误信息如下:
Warning: An error occurred while processing a template (entityName is not defined). Use --force to continue.
最佳答案
我现在通过这样做解决了它:
'string-replace': {
inline: {
files: {
'entity/templates/': 'entity/templates/*',
},
options: {
replacements: [{
pattern: /Article/g,
replacement: '<%= entityName ENDTAG'
}, {
pattern: /article/g,
replacement: '<%= _.slugify(entityName) ENDTAG'
}, {
pattern: /ENDTAG/g,
replacement: '%>'
}]
}
}
}
关于node.js - EJS 在 gruntfile 中转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21556642/