mb14
mb14

Reputation: 22596

choosing assets sailsjs

I've started using SailsJS for a small web app and so far it's great. However I'm struggling with the assets and layout.

Basically I would like to be able to use different type of assets (groups of css files) depending on the page. For this, I wrote 2 different layouts, each should includes the correct css files. However, when I add those files in the config/assets.js files there all bundled together. Is there a way to specifiy in my layout which assets i want to use ? I know you can specify assets.js or assets.styles but I would like to be able to create my own group .

I also tried to put those assets in a different directory (public for example) and load them manually in my layout. It's still not working because the server doesn't want to 'serve' them.

Any idea ?

Upvotes: 3

Views: 1609

Answers (2)

user4707474
user4707474

Reputation:

I know this is old, but in case anyone else comes across this; in recent versions of sails the asset pipeline is built around grunt by default (I haven't used sails before 0.10.x).

You can add your own exports in tasks/pipeline.js and link those to the appropriate location in tasks/config/sails-linker.js. E.g. you could have a views/public folder and tell sails-linker to inject publicCSS vars there. Then adjust your layout.ejs so that it imports the styles/javascript from whichever folder.

Upvotes: 1

mikermcneil
mikermcneil

Reputation: 11271

Glad you're liking Sails :)

For now, you can (a) bring in all styles all the time and make only the relevant ones apply (b) use another tool (like Grunt) to bundle assets like you would in a vanilla node.js project or (c) link the stylesheets manually (put them in your public folder).

As for the roadmap-- the community is working on more options for serving templates/styles/client-side logic. There's an open spec here:

https://github.com/balderdashy/sails/issues/240

Hope that helps!

Upvotes: 6

Related Questions