Get livereload to work with Sails.js

后端 未结 2 1622
情歌与酒
情歌与酒 2020-12-17 03:40

I am new to both Sails and grunt so I might be missing the obvious. I am trying to automatically refresh my sails app in the browser whenever files change.

相关标签:
2条回答
  • 2020-12-17 04:05
    1. Add livereload option to tasks/config/watch.js
        module.exports = function(grunt) {
    
         grunt.config.set('watch', {
            api: {
    
                // API files to watch:
                files: ['api/**/*', '!**/node_modules/**']
            },
            assets: {
    
                // Assets to watch:
                files: ['assets/**/*', 'tasks/pipeline.js', '!**/node_modules/**'],
    
                // When assets are changed:
                tasks: ['syncAssets' , 'linkAssets']
            },
            // ADD THIS 
            options: {
              livereload: true,
            },
        });
    
        grunt.loadNpmTasks('grunt-contrib-watch');
    };
    
    1. Add livereload script to your layout, somewhere at the end before </body> tag, by default to views/layout.ejs:
    <script src="http://localhost:35729/livereload.js"></script>
    

    Except of localhost you can use IP or DNS name of server

    This will refresh page if a file is changed in api or assets folder.

    By default Ggrunt-contrib-watch uses 35729 port. You can point other port like livereload: 8000

    • Similar question, but not so detailed answer
    • Ggrunt-contrib-watch docs

    EDIT: Well, I do not really know if this is totally correct, but looks like you can override layout settings in config/env/development.js. Add something like:

    module.exports = {
        views: {
            layout: 'dev'
        }
    }
    

    Then you can create separate layout file views/dev.ejs where you can add livereload script and other development params. Also you can add livereload key in the same way.

    0 讨论(0)
  • 2020-12-17 04:05

    After lost some time trying do this with sails/grunt, i install the livereload browser plugin (http://livereload.com/extensions/) for .html, js and css and the package (https://www.npmjs.com/package/sails-hook-autoreload) for the models and controllers.

    Works like a charm.

    0 讨论(0)
提交回复
热议问题