Sails.js指定要从自动插入中排除的JS文件

我试图设置我的帆应用程序使用Browserify(这是工作正常)。 不过,我不想将非浏览过的文件自动注入到我的网页中。

在我的tasks/pipeline.js文件中,我试过这个(我需要浏览的js文件在browserify目录中):

 // Client-side javascript files to inject in order // (uses Grunt-style wildcard/glob/splat expressions) var jsFilesToInject = [ // Load sails.io before everything else 'js/dependencies/sails.io.js', // Dependencies like jQuery, or Angular are brought in here 'js/dependencies/**/*.js', // All of the rest of your client-side js files // will be injected here in no particular order. 'js/**/*.js', // Ignore browserify directory '!js/browserify/**/*' ]; 

但是这不起作用,我的非浏览文件被注入到网页中。 我是Sails的新手,所以很可能这不是实现这一目标的正确方法。 任何build议将不胜感激。

它其实很容易,根本就不把**放在那里。 **通配符意味着recursionsearch。 我要做的是以下几点:

 var jsFilesToInject = [ // Load sails.io before everything else 'js/dependencies/sails.io.js', // Dependencies like jQuery, or Angular are brought in here 'js/dependencies/**/*.js', // All of the rest of your client-side js files // will be injected here in no particular order. 'js/*.js', //all files directly in .js folder will be included, but any folders not specified above will not ]; 

然后,如果你添加一个文件夹到你真正想要包含的js目录,只要确保在依赖关系和最后一行之间指定它就像

 'js/folderIWantToInclude/**/*.js' 

不要忘记,这个咕噜声将所有文件复制到.tmp,有时候您需要手动清除它,这样才能生效。 我也build议访问Gruntconfiguration文件文档作为参考 – 它是咕that,这是否包含,而不是风帆。

您可以通过使用“排除”(!)运算符来排除文件,如下所示:

 var cssFilesToInject = [ 'styles/**/*.css', '!styles/ie8.css', '!styles/ie9.css' ]; // Client-side javascript files to inject in order // (uses Grunt-style wildcard/glob/splat expressions) var jsFilesToInject = [ // Load sails.io before everything else 'js/dependencies/sails.io.js', // Dependencies like jQuery, or Angular are brought in here 'js/dependencies/**/*.js', // All of the rest of your client-side js files // will be injected here in no particular order. 'js/**/*.js', "!js/dependencies/respond/respond.src.js", ]; 

您可以按照自己的方式工作,并快速修复:在pipeline.js末尾,replace下面的代码块:

 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; }); 

 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; }); 

正如你所看到的,原来的代码会将tmp文件夹的相对path加到给定的规则上,从而导致! 在最后的道路中间某处。 有关完整的解释, 请参阅我对一个非常类似的问题的回答 。