2016-07-31 4 views
0

http://fomoapp-melbourne.rhcloud.comhttp://localhost:8000companies-list.component.tsevents-list.component.ts의 두 파일로 대체하려는 app 폴더가 있습니다. 나는 grunt-replace-string 플러그인을 사용하려고 시도하고 있는데, 이것은 겉으로보기에는 녹색의 Done 결과와 오류없이 성공적으로 실행되지만 대체는 발생하지 않습니다.그란트 문자열 교체가 작동하지 않습니다.

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']); 
}; 

답변

1

꿀꿀 거리는 소리 Files object는 대상 파일에 소스 파일의 매핑을 지정하는 것입니다 : 여기

처럼 Gruntfile.js 보이는 방법이다. 이 매핑의 목적은 Grunt가 소스 파일의 내용을 가져 와서 내용에 무언가를 수행 한 다음 대상 폴더의 새 파일에 응답을 쓰도록 지시하는 것입니다.

귀하의 구성에서 Grunt가 app/디렉토리에있는 두 개의 파일을 다시 쓰길 원합니다. 이것은 효과가 없을 것입니다. 난 당신이 자세한 옵션 grunt --verbose와 꿀꿀를 실행하는 경우, 귀하의 출력은 다음이 포함됩니다 내기 것이다 : 당신이 그들의 상대 경로를 지정해야하기 때문에 그런트는 원본 파일을 찾을 수 없기 때문에

Files: [no src] -> ./app/ 

이입니다.

앱을 구성하는 방법은 다르지만 src/폴더와 app/아래에 dist/folder가 있어야 할 수 있습니다. 당신이 build your files objects dynamically 선택할 경우, 설정은 다음과 같이 보일 수 있습니다 또한

files: [{ 
    expand: true, 
    cwd: './app/src/', 
    dest: './app/dest/', 
    src: ['companies-list.component.ts', 'events-list.component.ts'] 
}] 

documentation for grunt-string-replace 상태 :

패턴이 문자열, 첫 번째 발생이 교체 될 경우, 명시된 바와 같이 on String.prototype.replac e.

이것은 당신이 당신의 문자열의 인스턴스를 교체 할 복수를 원한다면, 당신은 Regular Expression literal를 제공해야한다는 것을 의미합니다. 예 :

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