Sails js - Creates a copy of assets

末鹿安然 提交于 2019-12-11 03:08:18

问题


We are considering porting our project to Sails.js. Our static assets are quite large - more than 3 GB. So, this has created a serious limitation as it doubles the size of our app. Can we modify Sails js to prevent this default behavior or can some one recommend some other framework?


回答1:


Sails uses Grunt to copy your assets into (by default) a clean .tmp/public folder every time the app is lifted. This allows you to pick and choose which assets should be made public, and also lets you compile and minify assets in different environments. This doesn't necessarily double the size of your app unless you're putting .tmp under version control, but if you have a lot of assets it can certainly make your app slow to start.

The simplest solution here is to turn off Grunt and serve your static assets directly from the assets folder. To do that:

  1. Delete the Gruntfile.js (or rename it to Gruntfile.js.bak)
  2. Create a new config file called config/assets.js (or whatever you like; the name doesn't matter), and put the following inside:

    module.exports = {
      paths: {
        public: __dirname+"/../assets"
      } 
    };
    

The reason to put this in a new config file rather than config/local.js is that local.js is in your .gitignore file by default, so if you're using Git for version control you'd have to recreate that file every time you install the app on a new machine.

Like I said, this is the simplest solution, but it has some drawbacks:

  • No more automatic compiling / minifying of assets in production mode
  • No more automatic linking of Javascript / CSS files using the asset pipeline

If you want to keep those features, but still avoid copying lots of files into .tmp, then the answer lies in modifying the default Grunt tasks (that's what they're in your project for!).




回答2:


In Sails.js 0.11 you may just add next code to .sailsrc file:

"hooks": {
 "grunt": false
}


来源:https://stackoverflow.com/questions/26119584/sails-js-creates-a-copy-of-assets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!