Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trouble with the auto-loading is that it's really hard to dictate the ordering of the source files in any meaningful way-- it really comes down to how you've structured the front-end.</p> <p>In v0.8.x (the version you're working with, from what I can tell), you can use the <code>config/assets.js</code> to control the ordering of folders that get loaded in. This is not ideal, but is a decent workaround that my team used on several projects.</p> <p>In v0.9, we've removed rigging/asset-rack in favor of tight integration Grunt, which has a large community and some really cool and well maintained packages for most types of asset bundling, etc.</p> <p>In any case, here are the different approaches you can investigate for serving assets in the new version of Sails.js:</p> <ol> <li><h3>Treat it just like anything else</h3> <p>In your <code>layout.ejs</code> file, create <code>&lt;link /&gt;</code> and <code>&lt;script&gt;&lt;/script&gt;</code> tags to link in your css and javascript files like you would normally. </p></li> <li><h3>Use AMD (Require.JS)</h3> <p>I think lots of folks would say this is actually the best option. Require is a pretty powerful tool. And I'm mostly in agreement-- if you're working with front-end javascript that could be coming from anywhere, and is going to be extended by other developers who may be using a different framework, AMD is a great way to make sure you stay safe. If you're using Require, each js file is its own module, and declares its own dependencies, so asset dependency management becomes a thing of the past. Then in production mode, there are a couple of different options to compile and minify your CSS and JS. You can even dynamically load templates and CSS from JS with Require, which is pretty neat. AMD/RequireJS is a hands-down winner if you're interested in loading some or all of your assets asynchronously. It's also an all-client-side solution, which is pretty cool.</p> <p>The only downside in my mind is the complexity. If you have control over the framework being used, you really shouldn't have to manually enter dependencies for each file-- it can figure that out itself (see <a href="https://github.com/balderdashy/mast/blob/2.x/lib/raise.js" rel="nofollow">https://github.com/balderdashy/mast/blob/2.x/lib/raise.js</a>)</p></li> <li><h3>Use Grunt</h3> <p>When you make a new project with <code>sails new foo</code> in Sails v0.9, a file called <code>Gruntfile.js</code> is created. It has lots of stuff in it, a lot of which isn't being used by default. You can do almost anything with Grunt, but in particular, you'll want to look at how it's set up to copy files from <code>assets/*</code> to <code>.tmp/public/</code>. </p></li> <li><h3><code>sails new foo --linker</code> (Sails v0.9 only)</h3> <p>Linker is a lot like what asset-rack/rigging does currently. It creates the same Gruntfile as #3 above, but utilizes more of the contents. It will auto-link files in the order you specify. Instead of view partials (e.g. <code>&lt;%= %&gt;</code>), the <code>scriptlinker</code> plugin allows you to customize the delimiters where js, css, and templates will be injected. By default, the Gruntfile is set up to use JST precompiled templates, but again, you can set it up however you like.</p></li> </ol> <p>Hope that helps guys, and best of luck!</p> <p>-Mike</p> <p>PS- v0.9 is coming out very very soon, I've just been working through tests and issues to make sure we're 100% there. If you'd like to try it out, check out:</p> <p><a href="https://gist.github.com/mikermcneil/5930330" rel="nofollow">https://gist.github.com/mikermcneil/5930330</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload