2017-05-05 57 views
1

我試圖更新應用程序以支持節點-v 7.7.3。但是,當我運行繁重的任務dom_munger按如下:Dom_munger問題與節點7.7.3 - 路徑必須是字符串

dom_munger:{ 
    read: { 
    options: { 
     read:[ 
     {selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs', isPath: true}, 
     {selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'} 
     ] 
    }, 
    src: 'app/index.html' 
    } 
} 

我收到錯誤:

Warning: Path must be a string. Received [ 'app/index.html' ] Use --force to continue. 

我不知道是否有改寫上述咕嚕任務的方式,或者有可能是一個很好的替代dom_munger。任何幫助,將不勝感激。

回答

0

grunt-dom-munger Github上:

When isPath is true, the extracted values are assumed to be file references and their path is made relative to the Gruntfile.js rather than the file they're read from.

嘗試刪除isPath財產,或改變它的路徑從Gruntfile匹配index.html文件。

+0

謝謝你!但是,如果Grunt和Index位於相同的文件夾結構中,這似乎只能工作。我的結構是這樣的: - /應用 -index.html - gruntfile.js 而如果沒有屬性「isPath」的dom_munger會找JS文件在同一目錄中,其中Gruntfile的地方。 – sandrasvensson

+0

@sandrasvensson但你有沒有嘗試刪除'isPath'屬性?它似乎解決了[這個類似的問題](https://github.com/cgross/grunt-dom-munger/issues/42)。 –

0

謝謝!但是,如果Grunt和Index位於相同的文件夾結構中,這似乎只能工作。我的結構是這樣的:

- /app 
    -index.html 
- gruntfile.js 

而且沒有屬性「isPath」的dom_munger會找JS文件在同一目錄中,其中Gruntfile的地方。

0

刪除isPath:true,並確保src屬性中的路徑相對於Gruntfile.js而不是它們從中讀取的文件。

如果需要進行更換路徑:

dom_munger: { 
    replacePath: { 
    options: { 
     callback: function($, file){ 
     var scripts = $('script[data-concat!="false"]'); 
     // NOTE: path is made relative to the Gruntfile.js rather than the file they're read from 
     for(var i=0, s, il=scripts.length; i<il; i++){ 
      s = scripts[i]; 
      if(s.attribs.src){ 
      s.attribs.src = s.attribs.src.replace('../', ''); 
      } 
     } 
     } 
    }, 
    src: 'temp/index.html' 
    }, 
    read: { 
    options: { 
     read: [ 
     {selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs'}, 
     {selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'} 
     ] 
    }, 
    src: 'temp/index.html' 
    } 
} 
相關問題