Gruntjs Grunt字符串替换不工作

Gruntjs Grunt字符串替换不工作,gruntjs,grunt-string-replace,Gruntjs,Grunt String Replace,我有一个app文件夹,我想在其中替换http://localhost:8000forhttp://fomoapp-melbourne.rhcloud.com在两个文件中:公司列表.component.ts和事件列表.component.ts。我尝试使用grunt replace string插件,它似乎运行成功,绿色Done结果,没有错误,但没有发生替换 以下是grunfile.js的外观: module.exports = function(grunt){ [ 'grunt-stri

我有一个
app
文件夹,我想在其中替换
http://localhost:8000
for
http://fomoapp-melbourne.rhcloud.com
在两个文件中:
公司列表.component.ts
事件列表.component.ts
。我尝试使用
grunt replace string
插件,它似乎运行成功,绿色
Done
结果,没有错误,但没有发生替换

以下是
grunfile.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']);
};
Grunt用于指定源文件到目标文件的映射。此映射的目的是告诉Grunt获取源中文件的内容,对内容执行某些操作,然后将响应写入目标文件夹中的新文件

从您的配置来看,您希望Grunt重写app/目录中的两个文件。这是行不通的。我敢打赌,如果使用verbose选项运行grunt,
grunt--verbose
,您的输出将包含以下内容:

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']
}]
此外,缔约国:

如果模式是字符串,则只替换第一个匹配项,如e中所述

这意味着,如果希望替换字符串的多个实例,则必须提供一个。例如:

replacements: [{
    pattern: /http:\/\/localhost:8000/g,
    replacement: 'http://fomoapp-melbourne.rhcloud.com'
}]