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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…