我正在尝试设置我的sails应用程序来使用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/**/*'
];
但是这不起作用,我的非浏览文件被注入到网页中。我对帆船还不熟悉,所以很有可能这根本不是达到目的的正确方法。任何建议都将不胜感激。
最佳答案
其实很简单,就是不要把**
放在那里。通配符表示递归搜索。我要做的是:
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'
别忘了,grunt将所有文件复制到.tmp,有时需要手动清除它,这样的更改才能生效。
我还建议您访问Grunt Configuration file docs以供参考-是grunt做了这个包含,而不是sails。
关于javascript - Sails.js指定要从自动插入中排除的JS文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29327025/