2

私は Grunt.js といくつかのプラグイン、特にgrunt-contrib-watch,grunt-nodemongrunt-contrib-coffee. 私はこれを 2 日間理解しようとしてきましたが、この時点で Grunt に関する私の知識が十分であるとは思いません。

私が経験している問題は、サーバー側の.coffeeファイルをコンパイルしてから nodemon にサーバーを再起動させ、その後 livereload 作業のみを行うことです。現在、Livereload は、サーバー側のcoffeeファイル以外のすべてに対して意図したとおりに機能します。contrib-watch変更を検出し、実行coffeeしてlivereloadイベントを発生させますが、その後nodemon再起動します。

nodemonページがリロードされる前に再起動して、画面に表示される内容がサーバー側のコードで行われている最新のものになるようにする方法はありますか?

別の端末タブで実行するオプションが提示されましたnodemonが、私は Windows を使用しており、この目的のために 1 つの端末を実行し続けたいと思ってい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'
  ]
4

4 に答える 4