Sails.js - How do I change the node.js module used by sails?

I want to write my own ejs-locals node module, but I also want the sails to use mine and I don't want to change the sails packages.json

.

How can I load, after sails have loaded their module ejs-locals

, my own module, to override it?

If there is a correct way to do things like this, I'd like to know :) Thanks.

I tried to find an answer to the official documentation there: http://sailsjs.org/#/documentation/concepts/extending-sails

But there is nothing about this.


Edit:

I tried to use the attribute fn

in config/views.js

but it doesn't work as expected, I made an example here: https://github.com/Vadorequest/sails-custom-ejs-locals


Final edit:

It works great with the solution suggested as the accepted answer, just disable layout

or it will mess up your config.layout: false

+3


source to share


3 answers


Hard disk configuration:



view: {
    engine: {
       ext: 'ejs',
       fn: yourfunction
   },
   // need to disabe sails.js default partials feature for dont auto load sails ejs-locals
   partial: false
}

      

+1


source


Try configuring the view engine in config / views.js.



...

ext : 'ejs',
fn: require('ejs-locals')

...

      

+1


source


You can use npm winding trimming. https://docs.npmjs.com/cli/shrinkwrap

Then edit npm-shrinkwrap.json

and under the sails section point ejs or ejs-lorals to your version

0


source







All Articles