Sails 0.9.x已移至使用Grunt处理资产。这使您可以进行多种不同的预编译和资产处理。默认情况下,无法将自动资产注入到视图和布局中。
我们添加了一个标记,您可以在生成新的sails项目时包括该标记,该项目将在您的资产文件夹中创建一个文件夹,并自动将所有文件注入到index.html或布局文件中。这仅应用于开发。
sails new <project name> --linker
现在,您将
linker在自己的资产文件夹下有一个标题为文件夹的文件夹,您可以在其中放置文件以使其自动链接。还将在您的
index.html文件和布局文件中添加一些标签,以了解在何处注入各种JS,CSS和模板。
您可以在此处阅读更多信息:Sails Wiki-资产
如果您正在使用已创建的项目,则可以手动创建以下文件结构:
assets/ linker/ js/ styles/ templates/
您还需要在视图中添加以下标签:
<!--scriptS-->All .js files in assets/linker/js will be included hereIn production mode, they will all be concatenated and minified<!--scriptS END--><!--STYLES-->All .css files in assets/linker/styles (including automatically compile ones from LESS) will be included hereIn production mode, they will all be concatenated and minified<!--STYLES END--><!--TEMPLATES-->All *.html files will be compiled as JST templates and included here.<!--TEMPLATES END-->
因此,要使用bootstrap并将文件自动添加到页面中,您将把bootstrap.js文件放入
assets/linker/js,并将bootstrap.css文件放入
assets/linker/css。
在生产中,您将需要编辑gruntfile,将所有的CSS和JS编译为单个文件,然后在view / layout / index.html中手动链接它们。



