SailsJS Linker(Grunt)忽略文件(Gruntfile.js) [英] SailsJS Linker (Grunt) Ignore files (Gruntfile.js)
问题描述
我正在使用Bower进行资产管理. Bootstrap Bower存储库随附了Gruntfile.js.
I am using bower for asset management. The Bootstrap bower repo is coming with a Gruntfile.js.
是否可以从链接程序中排除它?
Is there a way to exclude this from the linker?
我尝试过:
var jsFilesToInject = [
'!**Gruntfile.js',
// ...
]
但是它不起作用-我是否将该字符串放在错误的位置?
But it's not working - am I putting this string in the wrong spot?
P.S. I followed this guide to get here: StackOverFlow Question and ran bower install bootstrap
and bower install angular
.
推荐答案
这是当前Sails前端生成器中的错误.我已经提交了PR ,但是现有应用程序必须手动修复,因为生成器仅执行一次.
This is a bug in the current sails frontend generator. I have submitted a PR, but existing applications will have to be fixed manually, since the generator is only executed once.
问题出在当前pipeline.js
文件的末尾,在实际导出设置的部分中.此刻它是这样的:
The issue is in the end of the current pipeline.js
file, in the section that actually exports the settings. At the moment it goes like this:
// pipeline.js
//... Defined rules ...
module.exports.cssFilesToInject = cssFilesToInject.map(function(path) {
return '.tmp/public/' + path;
});
module.exports.jsFilesToInject = jsFilesToInject.map(function(path) {
return '.tmp/public/' + path;
});
module.exports.templateFilesToInject = templateFilesToInject.map(function(path) {
return 'assets/' + path;
});
如您所见,它在模板的tmp
文件夹或assets
文件夹前面添加了相对路径.这导致规则
.tmp/public/!js/foo.js
中的!js/foo.js
,可能与任何内容都不匹配.
As you can see it prepends the relative path to the tmp
folder or the assets
folder for templates. This results in the rule
!js/foo.js
in .tmp/public/!js/foo.js
, which will probably not match anything.
解决方案是将pipeline.js
中的上面的块替换为以下内容:
The solution is to replace the block above in pipeline.js
with the following:
module.exports.cssFilesToInject = cssFilesToInject.map(function(path) {
var tmpPath = '.tmp/public/';
if (path.substring(0,1) == '!')
return '!' + tmpPath + path.substring(1);
return tmpPath + path;
});
module.exports.jsFilesToInject = jsFilesToInject.map(function(path) {
var tmpPath = '.tmp/public/';
if (path.substring(0,1) == '!')
return '!' + tmpPath + path.substring(1);
return tmpPath + path;
});
module.exports.templateFilesToInject = templateFilesToInject.map(function(path) {
var tmpPath = 'assets/';
if (path.substring(0,1) == '!')
return '!' + tmpPath + path.substring(1);
return tmpPath + path;
});
这将检查给定规则是否以!
开头并正确添加,因此!js/foo.js
将导致!.tmp/public/js/foo.js
正确匹配.
This will check if the given rule starts with an !
and prepend it correctly, so !js/foo.js
will result in !.tmp/public/js/foo.js
that will correctly match.
必须在创建结果集后设置排除项.这是根据 grunt的文档.因此,对于您而言,应该是:
The exclusions have to be set AFTER the result set was created. This is according to grunt's documentation. So for your case it would be:
var jsFilesToInject = [
//...
'!**Gruntfile.js',
]
这篇关于SailsJS Linker(Grunt)忽略文件(Gruntfile.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!