2014-12-19 6 views
0

다음은 특정 줄만 바꾸려는 클래스입니다. 내가 grunt.loadNpmTasks('grunt-string-replace');그란트 : 특정 단어를 줄 바꾸기

어떤 도움이 감사를 사용하고

myfunc('`MyFunction/myControl`'); 

:

class abc{ 

    Rest of code... 

    Titan.include('`MyFunction/myControl`.js'); 

    Rest of code... 

} 

나는 myfuncTitan.include를 교체하고 줄에서 단어 "의 .js"를 제거합니다. 당신이 사용하는 경우

+1

좋아, 그럼 뭐 해봤 어? 오류가 있습니까? 우리는 문제가 무엇인지 알지 못합니다. – jakerella

+0

@jakerella 나는 아래 것을 시도했다. 하지만 파일의 첫 번째 줄만 바꿀 수 있었고 다른 줄은 동일했습니다. DIST : { 파일 : [{ 확장 : 사실, CWD : '자원 /', SRC : '**/* JS.', 대상 : '자원 /' }], 옵션 : { 교체 : [{ 패턴 : 'Titan.include', 교체 '이 myfunc' }] } } – Bhavin2887

답변

1

는 다음과 같은 방법으로 구성 할 수 있습니다 플러그인 꿀꿀 텍스트를 교체하기 : 어쨌든

replace: { 
     myReplace: { 
     src: [ 'yourFile' ], //your file 
     dest: 'destinationFile', //path and namefile where you will save the changes. 
     replacements: [ { 
      from: /Titan\.include\('(.*)\.js'\);/g, //Regexp to match what you need 
      to: "myfunc('$1');" //Replacement for the Regexp 
     } ] 
     } 
    } 

, 나는 꿀꿀 - 문자열 대체 플러그인을 사용하지,하지만 결코 대신 그것을 사용해야하는 경우 grunt-text-replace 나는 이런 식으로 일해야한다 :

'string-replace': { 
    dist: { 
    files: { 
     'dest/': 'yourfile' //Key: path where you will save the changes. Value: File or path where you will search. 
    }, 
    options: { 
     replacements: [{ 
     pattern: /Titan\.include\('(.*)\.js'\);/g, 
     replacement: "myfunc('$1');" 
     }] 
    } 
    } 
+0

파일 : [{ 확장 : 사실, CWD : '자원 /', SRC를 '**/* .js ', dest :'Resources/' }]이 매개 변수는 파일에 없습니다. – Bhavin2887