2014-01-25 38 views
3

如何指定用于凉亭组件的默认文件,以便通过grunt-bower-install正确注入?为组件配置Grunt-Bower-Install路径

我正在与datejs合作,根据您的本地化他们有不同的文件。我想包括的文件不在bower_components根/ datejs目录,所以我得到的错误:

datejs was not injected in your file.

Please go take a look in "app/bower_components/datejs" for the file you need, then manually include it in your file.

我想我最难避免硬编码datejs到我的索引文件并没有真正想要将“date-en-US.js”文件移动到datejs目录的根目录中。

这是datejs凉亭组件的结构。

bower_components 
└── datejs 
    └── build 
     └── ... 
     └── date-en-US.js 
     └── ... 
    └── src 
    └── test 

和公正的情况下,这会有所帮助,这是位于datejs的.bower.json文件凉亭组件路径:

{ 
    "name": "datejs", 
    "homepage": "https://github.com/datejs/Datejs", 
    "_release": "7bdddb55d6", 
    "_resolution": { 
    "type": "branch", 
    "branch": "master", 
    "commit": "7bdddb55d69719e42c358c3a2b7df706ff3090f8" 
    }, 
    "_source": "git://github.com/datejs/Datejs.git", 
    "_target": "*", 
    "_originalSource": "datejs", 
    "_direct": true 
} 

回答

7

对派对稍迟,但您可以覆盖回购的主要属性,以定义您想要注入到您的应用程序的任何文件。要做到这一点,你需要使用overrides财产YOURbower.json

试试这个:

{ 
    "name": "name", 
    "version": "x.x.x", 
    "dependencies": { 
    "datejs": "x.x.x" 
    }, 
    "overrides": { 
    "datejs": { 
     "main": "build/date-en-US.js" 
    } 
    } 
} 
+0

确实!关于[wiredep](https://github.com/taptapship/wiredep#bower-overrides)的更多解释,请参阅[grunt-wiredep](https://github.com/stephenplusplus/grunt-wiredep#behind-幕后)。 Thx @nknj – pgu

1

尝试在繁重的文件中添加此:

'bower-install': { 
    fileTypes: { 
     fileExtension: { 
      detect: { 
       typeOfBowerFile: /-en-US.js/ 
      } 
     } 
    } 
} 

我没有试过,我的正则表达式可能关闭。但根据grunt-bower-install readme,它指出See [wiredep's](https://github.com/stephenplusplus/wiredep) readme for more options of customization并在那里显示使用上述配置。基本上 - grunt-bower-install不知道要寻找什么。此选项似乎告诉它该信息。

3

我也很沮丧这几次。我在我的案例中发现的是,“grunt bower-install”需要.bower.json中的一个“main”条目。它是一个字符串或字符串数​​组,指向应该安装的相关JS和/或CSS文件。

在你的情况下,我没有看到“主”,并建议你创建一个包含所需的datejs文件。我会建议源文件,如果你打算使用grunt缩小/等。您可以查看其他成功的组件以查看“主”条目的示例。

我怀疑有些组件没有提供条目,因为它们没有单一的使用模式(即可以混合和匹配所需的文件),但这只是我的推测。

+0

谢谢!我有一种感觉就是这样。但是,如果我将来更新我的凉亭组件,会发生什么情况? .bower.json文件中的更改是否会被覆盖? – adam8810

+1

可耻地我承认,我可能更像是一个小甜甜,然后你设想。如果一位更有资格的专家看到这个和评论,我会更新我的回应。我还没有测试过更新用例。为了保护自己,我强制将.bower.json文件放入我的源代码控制中,至少可以看到任何更新。在一个案例中,我开发了一个github问题,因为我认为他们可以自己改变它。但是,“main”可能是许多文件或文件组合之一的用例似乎不受Bower的支持。然而,我没有足够的资格来提出这一申诉。 – corporatedrone

+0

@corporatedrone,作为一个单独的答案回答了这个问题 – nknj