grunt的安装使用

目前 Grunt 的安装有些改变, grunt-cli 全局安装, 而 grunt 安装在本项目.

$ npm install grunt-contrib-watch –save-dev

$npm install grunt-nodemon –save-dev

$npm install grunt

加上–save-dev可以让本地添加的插件自动添加到项目的依赖中去。

安装完以后,配置gruntfile.js文件。根据自己的目录要做修改。

module.exports = function(grunt) {

  grunt.initConfig({
    watch: {
      jade: {
        files: ['views/**'],
        options: {
          livereload: true
        }
      },
      js: {
        files: ['public/js/**', 'models/**/*/js', '/schemas/**/*.js'],
        //tasks: ['jshint'],
        options: {
          livereload: true //当文件出现改动的时候会重新启动服务
        }
      }
    },
    nodemon: {
      dev: {
        options: {
          file: 'app.js',
          args: [],
          ingoredFiles: ['README.md', 'node_modules/**', '.DS_Store'],
          watchedExtensions: ['js'],
          watchedFolders: ['./'],
          debug: true,
          delayTime: 1,
          env: {
            PORT: 3000
          },
          cwd: __dirname
        }
      }
    },

    concurrent: {
      tasks: ['nodemon', 'watch'],
      options: {
        logConcurrentOutput: true
      }
    }
  })

  grunt.loadNpmTasks('grunt-concurrent');//优化慢任务 如less coffee
  grunt.option('force', true);//不要因为语法或警告中断整个grunt
  grunt.registerTask('default', ['concurrent']);//通过concurrent的tasks传入nodemon和watch 可以执行这两个任务
}

所以,有文件修改了grunt会自动重启,就不用每次都重新node app.js了。

在项目目录下执行

$grunt

出现以下信息,证明运行成功。
Running “concurrent:tasks” (concurrent) task
Running “nodemon:dev” (nodemon) task
Running “watch” task
Waiting…
[nodemon] 1.9.2
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node app.js

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值