如何在风帆 0.9 中提供引导程序模板? [英] How to serve a bootstrap template in sails 0.9?

查看:36
本文介绍了如何在风帆 0.9 中提供引导程序模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过较新的风帆版本提供引导模板.我应该将 JS 的链接更新为其他内容吗?我尝试在资产文件夹中移动 js 和图像,但 javascript 不起作用.关于这个主题的sails 文档很差.谁能告诉一个简单的方法来集成它.提前致谢

I wanted to know how to serve a bootstrap template through newer sails version . Should I update the links of JS to something else . I tried moving js and images in asset folder but javascript didn't work . The sails documentation is very poor on this topic . Can anyone tell a easy way to integrate it . Thanks in advance

推荐答案

Sails 0.9.x 已转向使用 Grunt 处理资产.这允许您进行许多不同类型的预编译和资产处理.默认情况下,您的视图和布局中的自动资产注入不可用.

Sails 0.9.x has moved to use Grunt for handling assets. This allows you to do many different kinds of pre-compilation and asset handling. By default, automatic asset injection into your views and layouts is not available.

我们添加了一个标志,您可以在生成新的风帆项目时包含该标志,该标志将在您的资产文件夹中创建一个文件夹,并自动将任何文件注入您的 index.html 或布局文件.这应该只用于开发.

We have added a flag you can include when generating a new sails project that will create a folder within your assets folder and automatically inject any files into you index.html or layout file. This should only be used for development.

sails new --链接器

现在您的资产文件夹下将有一个名为 linker 的文件夹,您可以将文件放入其中以自动链接它们.它还会向您的 index.html 文件和布局文件添加一些标签,以了解在哪里注入各种 JS、CSS 和模板.

Now you will have a folder titled linker under your assets folder that you can place files in to have them automatically linked. It will also add some tags to your index.html file and your layout file to know where to inject the various JS, CSS and templates.

您可以在此处阅读更多信息:Sails Wiki - 资产

You can read more here: Sails Wiki - Assets

如果您正在使用已经创建的项目,您可以手动创建以下文件结构:

If you are working with a project that has already been created you can manually create the following file structure:

assets/
  linker/
    js/
    styles/
    templates/

您还需要将以下标签添加到您的视图中:

You will also need to add the following tags to your view:

<!--SCRIPTS-->
All .js files in assets/linker/js will be included here
In 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 here
In 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.

So to use bootstrap and have the files automatically added to your page you will place the bootstrap.js files into assets/linker/js and the bootstrap.css file into assets/linker/css.

在生产环境中,您需要编辑 gruntfile 以将所有 css 和 js 编译为单个文件,并在您的视图/布局/index.html 中手动链接它们.

In production you will want to edit the gruntfile to compile all of your css and js into single files and manually link them in your view/layout/index.html.

这篇关于如何在风帆 0.9 中提供引导程序模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆