注意:以下答案不再与当前版本的 SailsJS 完全相关,因为从 SailsJS 0.10 开始不支持链接器文件夹。
见:Sails not generating linker
原答案:
我能够为此找到一个解决方案,这实际上非常简单。我没有意识到您可以配置 bower 放置文件的位置。
创建一个 .bowerrc 文件并更改安装 bower 组件的目录,如果是 Sailjs,则应将它们放入 assets 文件夹中。
/*
* Create a file called .bowerrc and put the following in it.
* This file should be in the root directory of the sails app.
*/
{
"directory": "assets/linker/bower_components"
}
然后,每当文件更改时,Sails 将使用 grunt 将它们复制到 .tmp/public/assets 文件夹。如果您不希望sails 不断删除然后重新复制这些文件,您可以将它们排除在grunt 文件中。
/*
* This is not necessary, but if you have a lot of components and don't want
* them constantly being deleted and copied at every file change you can update
* your Gruntfile.js with the below.
*/
clean: {
dev: ['.tmp/public/**',
'!.tmp/public',
'!.tmp/public/bower_components/**'],
build: ['www']
},
使用 requirejs 和sails 的一个技巧。默认情况下,你会从 socket.io 文件中得到一个错误,因为sails 会在不使用 requirejs 的情况下加载它。这会抛出一个错误,因为 socket.io 支持 amd 样式加载,更多细节在这里http://requirejs.org/docs/errors.html#mismatch。
解决此问题的最简单方法是注释掉 socket.io.js 末尾附近的行。
/*
* Comment the below out in the file assets/js/socket.io.js, if using requirejs
* and you don't want to modify the default sails setup or socket.io.
*/
if (typeof define === "function" && define.amd) {
define([], function () { return io; });
}
另一种方法是将assets/js中名为“socket.io.js”、“sails.io.js”和app.js的sails文件重新编码为amd模块。