【发布时间】:2014-11-26 16:27:24
【问题描述】:
我想使用grunt-hash 插件来重命名我的 js 文件。 此插件创建一个包含重命名文件映射的新文件:
hash: {
options: {
mapping: 'examples/assets.json', //mapping file so your server can serve the right files
现在我需要通过替换所有用法(将“index.js”重命名为“index-{hash}.js”)来修复指向此文件的链接,因此我想使用grunt-text-replace 插件。 根据文档,我需要配置替换:
replace: {
example: {
replacements: [{
from: 'Red', // string replacement
to: 'Blue'
}]
}
}
如何读取 json 映射文件以获取每个文件的 {hash} 值并提供它们来替换任务?
【问题讨论】:
-
@Future reader:如果你只是想读入一个文件,使用
grunt.file.read