gpt4 book ai didi

node.js - EJS 在 gruntfile 中转义

转载 作者:搜寻专家 更新时间:2023-11-01 00:45:00 24 4
gpt4 key购买 nike

我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com