我有一个app文件夹,我想在两个文件中替换http://fomoapp-melbourne.rhcloud.com的http://localhost:8000:companies-list.component.ts和events-list.component.ts。我试图使用grunt-replace-string插件,它似乎成功地运行绿色Done的结果,没有错误,但没有更换发生。
下面是Gruntfile.js的样子:
module.exports = function(grunt){
[
'grunt-string-replace',
].forEach(function(task){
grunt.loadNpmTasks(task);
});
// configure plugins
grunt.initConfig({
'string-replace': {
dist: {
files: {
'./app/': ['companies-list.component.ts','events-list.component.ts'],
},
options: {
replacements: [{
pattern: 'http://localhost:8000',
replacement: 'http://fomoapp-melbourne.rhcloud.com',
}]
}
}
},
});
// register tasks
grunt.registerTask('default', ['string-replace']);
};发布于 2016-08-01 02:20:56
Grunt 文件对象用于指定源文件到目标文件的映射。此映射的目的是告诉Grunt获取源文件的内容,对内容做一些操作,然后将响应写入目标文件夹中的一个新文件。
在我看来,从您的配置来看,您希望Grunt重写应用程序/目录中的两个文件。这不管用。我敢打赌,如果您使用详细选项grunt --verbose运行grunt,您的输出将包含以下内容:
Files: [no src] -> ./app/这是因为Grunt无法找到源文件,因为您需要指定它们的相对路径。
这取决于您如何构建应用程序,但是您可能希望在app/下有一个src/文件夹和一个dist/文件夹。如果选择动态构建文件对象,您的配置可能如下所示:
files: [{
expand: true,
cwd: './app/src/',
dest: './app/dest/',
src: ['companies-list.component.ts', 'events-list.component.ts']
}]此外,咕噜-字符串的文档.替换声明:
如果模式是字符串,则将只替换第一个匹配项,如String.prototype.replace中所述。
这意味着,如果要替换字符串的多个实例,则必须提供一个正则表达式文字。例如:
replacements: [{
pattern: /http:\/\/localhost:8000/g,
replacement: 'http://fomoapp-melbourne.rhcloud.com'
}]https://stackoverflow.com/questions/38689136
复制相似问题