Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

node.js - How to serve a bootstrap template in sails 0.9?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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 <project name> --linker

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.

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-->

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...