首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在浏览器刷新时使用咕噜

在浏览器刷新时使用咕噜
EN

Stack Overflow用户
提问于 2017-03-27 05:18:43
回答 1查看 4.4K关注 0票数 5

目前,每次更改服务器文件时,我都会使用browser-refresh重新启动节点服务器。我想更进一步,每次更改HTML文件时都要刷新/重新加载我的浏览器。我正在为客户端使用工具栏,所以我在我的.hbs目录中有views文件。我原以为browser-refresh也能刷新浏览器,但它对我不起作用。

对于grunt,我安装了以下任务:

代码语言:javascript
复制
grunt.loadNpmTasks('grunt-express-server');
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-express-runner');

我不认为我需要所有这些,但我想找到有用的东西。我可以用grunt-exec重新启动我的服务器,但是我已经有了browser-refresh的别名,所以我并不需要这个别名。

我还应该注意,在我的app.js服务器文件中,我使用的是app.use('/', routes); where var routes = require('./routes/index');。因此,当我的应用程序加载(使用node app.js)时,它直接进入http://localhost:3000/users/login

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-27 17:58:24

使用咕噜-表并将活重装选项设置为true,将启用活动重新加载和自动重建。

例如,在您的gruntfile.js中:

代码语言:javascript
复制
watch: {
  css: {
    files: '**/*.sass',
    tasks: ['sass'],
    options: {
      livereload: true,
    },
  },
},

对于站点的重建,(使用咕噜-表插件),只需键入

grunt watch

若要在更改时自动重新构建网站,请查看下面grunt watch命令的示例用法:

gruntfile.js

代码语言:javascript
复制
module.exports = function (grunt) {

  grunt.initConfig({

    exec: {
      server: 'node server'
    },

    // Other JS tasks here
    // ...


    watch: {
      css: {
        files: ['scss/**/*.scss'],
        tasks: ['sass'],
        options: {
          spawn: false
        }
      },

      javascript: {
        files: ['js/*.js'],
        tasks: ['uglify']
      },

      options: {
        livereload: true,
      },

    },

  });

  grunt.registerTask('server', ['exec:server']);

  // Minify JS and create CSS files
  grunt.registerTask('build', ['uglify', 'sass']);

  // Do what you expect the default task to do
  grunt.registerTask('default', ['build', 'exec:server']);
};

更多信息在这里:https://github.com/gruntjs/grunt-contrib-watch/blob/master/docs/watch-examples.md#enabling-live-reload-in-your-html

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43038438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档