2017-05-05 55 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' 
    } 
} 
相关问题