Grunt:contrib-watch编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

剃须胡须

我一直有与Grunt.js和几个插件,尤其是一个问题:grunt-contrib-watchgrunt-nodemongrunt-contrib-coffee我已经尝试解决了两天,但是我现在对Grunt的了解还不足以解决这个问题。

我遇到的问题很简单,就是我要.coffee编译服务器端文件,然后让nodemon重新启动服务器,然后再进行livereload工作。现在,Livereload可以按预期工作,但服务器端coffee文件除外contrib-watch检测到更改,运行coffee并触发livereload事件,然后nodemon重新启动。

有没有一种方法可以nodemon在页面重新加载之前重新启动,以使我在屏幕上看到的内容与服务器端代码中的最新信息一致?

已经为我提供了仅nodemon在单独的终端选项卡上运行的选项,但是我在Windows上,因此更愿意让一个终端运行以达到此目的,这就是我正在使用的全部原因grunt-concurrent

这是我的Gruntfile,现在还处于初期阶段(因为我试图弄清所有这些)。如果您希望我将其编译为JavaScript,然后发表评论并提出要求,我将很高兴。

module.exports = (grunt) ->

  # configuration
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'

    # watch task
    watch:
      css:
        files: ['src/assets/styles/**/*.styl']
        tasks: ['stylus']
        options:
          livereload: true
      coffee:
        files: ['src/**/*.coffee']
        tasks: ['coffee']
      js:
        files: ['**/*.js']
        options:
          livereload: true
      jade:
        files: ['views/**/*.jade']
        options:
          livereload: true

    # compile coffeescript to javascript
    coffee:
      compile:
        options:
          sourceMap: true
        files: [
          expand: true
          cwd: 'src/'
          src: ['**/*.coffee']
          dest: ''
          ext: '.js'
        ]

    # compile stylus to css
    stylus:
      compile:
        files: [
          expand: true
          cwd: 'src/assets/styles/'
          src: ['**/*.styl']
          dest: 'assets/styles/'
          ext: '.css'
        ]

    # run server
    nodemon:
      dev:
        options:
          file: 'server.js'
          watchedExtensions: ['js', 'json']
          ignoredFiles: [
            'assets/**',
            'node_modules/**',
            '**/.js.map'
          ]

    # run tasks concurrently for fast builds
    concurrent:
      first:
        tasks: ['coffee', 'stylus']
        options:
          logConcurrentOutput: true
      second:
        tasks: ['nodemon', 'watch']
        options:
          logConcurrentOutput: true

  # load dependencies
  require('load-grunt-tasks') grunt

  # register tasks
  grunt.registerTask 'default', [
    'concurrent:first',
    'concurrent:second'
  ]
Ben

我自己没有使用过,但是前一段时间遇到了:grunt-rerun与监视任务结合使用,您可以暂停长时间运行的任务,例如express(但也可以与nodemon一起使用),运行一些任务,然后再次启动该任务。示例配置如下所示:

grunt.initConfig({
  watch: {
      dev: {
        files: ['server/*.js'],

        //Note the :go flag used for sending the reload message to the rerun server
        tasks: ['clean','rerun:dev:express:go']
      },
    },
    express: {
        dev: {
            options: {
                port: 3000,
                bases: ['/public'],
                keepalive: true,
                server: path.resolve('./server/app.js')
            }
        }
    },
    // Configuration to be run (and then tested).
    rerun: {
      dev: {
        options: {
          tasks: ['express']
        },
      },
    }
})

https://npmjs.org/package/grunt-rerun

我不确定实时重新加载。我的猜测是因为它关闭了进程,通过生成一个新进程将重新加载该页面,但是我没有亲自使用过,因此我不确定。

第二种选择是,使用支持多个选项卡的命令提示符,例如Console我是Mac用户,因此我使用具有多个窗格的iTerm 2大部分的时间,我每个项目四开,对watchtestem支持PHP的服务器和其他一切壳。您可能会发现这更快,更省事。

只是关于Coffeescript的简短说明,许多JavaScript开发人员都没有使用它,因此为了让更多的读者了解您的源代码,您发布问题之前将coffee编译为js可能是一个好习惯

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Grunt:contrib-watch当编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

来自分类Dev

如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

来自分类Dev

带livereload的grunt-contrib-watch,带vs,不带grunt-contrib-connect,带livereload

来自分类Dev

为什么grunt-contrib-watch livereload无法正常运作?

来自分类Dev

grunt-contrib-watch + grunt-rsync

来自分类Dev

grunt-contrib-connect:当浏览器打开时,grunt服务器停止

来自分类Dev

如何使用grunt http服务器访问区域设置json文件(grunt-contrib-connect)

来自分类Dev

带有contrib-watch的grunt-express服务器

来自分类Dev

服务器端包括(SSI)和grunt connect Web服务器

来自分类Dev

服务器端包括(SSI)和grunt connect Web服务器

来自分类Dev

grunt-contrib-watch + sass:如何指定目标文件?

来自分类Dev

grunt-contrib-sass无法编译CSS文件

来自分类Dev

使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

来自分类Dev

grunt-contrib-watch:{tinylr:“ Welcome”,版本:“ 0.0.4”}

来自分类Dev

Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

来自分类Dev

grunt-contrib-watch未绑定递归错误

来自分类Dev

grunt-contrib-watch是否有不同的输出样式?

来自分类Dev

使用grunt-contrib-handlebars版本问题预编译车把

来自分类Dev

grunt-contrib-connect服务器无法连接本地主机

来自分类Dev

grunt-contrib-connect:仅root可访问,仅在CI服务器上

来自分类Dev

如何在Ubuntu服务器12.04 64中安装grunt-contrib-qunit?

来自分类Dev

Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

来自分类Dev

Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

来自分类Dev

在Visual Studio 2013中使用Grunt(无grunt-contrib)来编译Bootstrap 3.1 LESS

来自分类Dev

在Visual Studio 2013中使用Grunt(无grunt-contrib)来编译Bootstrap 3.1 LESS

来自分类Dev

指定事件时在服务器端写入文件的有效方法

来自分类Dev

运行grunt-contrib-imagemin时出错

来自分类Dev

运行grunt-contrib-imagemin时出错

来自分类Dev

触发Web用户控件的任何服务器端事件时如何停止刷新当前页面

Related 相关文章

  1. 1

    Grunt:contrib-watch当编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

  2. 2

    如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

  3. 3

    带livereload的grunt-contrib-watch,带vs,不带grunt-contrib-connect,带livereload

  4. 4

    为什么grunt-contrib-watch livereload无法正常运作?

  5. 5

    grunt-contrib-watch + grunt-rsync

  6. 6

    grunt-contrib-connect:当浏览器打开时,grunt服务器停止

  7. 7

    如何使用grunt http服务器访问区域设置json文件(grunt-contrib-connect)

  8. 8

    带有contrib-watch的grunt-express服务器

  9. 9

    服务器端包括(SSI)和grunt connect Web服务器

  10. 10

    服务器端包括(SSI)和grunt connect Web服务器

  11. 11

    grunt-contrib-watch + sass:如何指定目标文件?

  12. 12

    grunt-contrib-sass无法编译CSS文件

  13. 13

    使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

  14. 14

    grunt-contrib-watch:{tinylr:“ Welcome”,版本:“ 0.0.4”}

  15. 15

    Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

  16. 16

    grunt-contrib-watch未绑定递归错误

  17. 17

    grunt-contrib-watch是否有不同的输出样式?

  18. 18

    使用grunt-contrib-handlebars版本问题预编译车把

  19. 19

    grunt-contrib-connect服务器无法连接本地主机

  20. 20

    grunt-contrib-connect:仅root可访问,仅在CI服务器上

  21. 21

    如何在Ubuntu服务器12.04 64中安装grunt-contrib-qunit?

  22. 22

    Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

  23. 23

    Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

  24. 24

    在Visual Studio 2013中使用Grunt(无grunt-contrib)来编译Bootstrap 3.1 LESS

  25. 25

    在Visual Studio 2013中使用Grunt(无grunt-contrib)来编译Bootstrap 3.1 LESS

  26. 26

    指定事件时在服务器端写入文件的有效方法

  27. 27

    运行grunt-contrib-imagemin时出错

  28. 28

    运行grunt-contrib-imagemin时出错

  29. 29

    触发Web用户控件的任何服务器端事件时如何停止刷新当前页面

热门标签

归档