Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何根据需要使用grunt-contrib-watch和grunt-contrib-coffee来编译CoffeeScript?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我保存的单个文件上运行咖啡和咖啡编译.我的项目中有数百个CoffeeScript文件,并且编译所有这文件需要太多时间.

这是我的Gruntfile:

@H_575_9@module.exports = (grunt) -> grunt.initConfig pkg: grunt.file.readJSON 'package.json' coffee: all: expand: true bare: true cwd: 'src/coffeescript/' src: '**/*.coffee' dest: 'public/js/compiled' ext: '.js' coffeelint: all: ['src/coffeescript/**/*.coffee'] watch: coffeescript: files: ['src/**/*.coffee'] tasks: ['coffeelint','coffee'] options: spawn: false grunt.event.on 'watch',(action,filepath) -> grunt.config(['coffeelint','all'],filepath) grunt.config(['coffee',filepath) grunt.loadNpmTasks 'grunt-coffeelint' grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-watch' grunt.registerTask 'default',['coffeelint','coffee','watch']

coffeelint任务仅在更改的文件上成功运行.

咖啡编译不产生任何JS文件,即使grunt说它运行.

保存一个咖啡文件后的输出是:

OK
>> File "src/coffeescript/app.coffee" changed.


Running "coffeelint:all" (coffeelint) task
>> 1 file lint free.

Running "coffee:all" (coffeE) task

Running "watch" task
Completed in 0.009s at Sat Feb 01 2014 13:10:07 GMT-0600 (CST) - WaiTing...

这里有什么问题?任何帮助将不胜感激!

更新:

这是一个工作示例:

@H_575_9@module.exports = (grunt) -> fs = require 'fs' isModified = (filepath) -> Now = new Date() modified = fs.statSync(filepath).mtime return (Now - modified) < 10000 grunt.initConfig coffee: options: sourceMap: true bare: true force: true # needs to be added to the plugin all: expand: true cwd: 'src/coffeescript/' src: '**/*.coffee' dest: 'public/js/compiled' ext: '.js' modified: expand: true cwd: 'src/coffeescript/' src: '**/*.coffee' dest: 'public/js/compiled' ext: '.js' filter: isModified coffeelint: options: force: true all: expand: true cwd: 'src/coffeescript/' src: '**/*.coffee' modified: expand: true cwd: 'src/coffeescript/' src: '**/*.coffee' filter: isModified watch: coffeescript: files: ['src/**/*.coffee'] tasks: ['coffeelint:modified','coffee:modified'] grunt.loadNpmTasks 'grunt-coffeelint' grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-watch' grunt.registerTask 'default',['coffeelint:all','coffee:all','watch']

解决方法

尝试添加一些这样的东西给你的c任务

coffee:
  all:
    filter: (filepath) ->
        fs = require('fs')
        Now = new Date()
        modified =  fs.statSync(filepath).mtime
        return (Now - modified) < 10000 # or another difference in millyseconds

阅读更多在documentation

大佬总结

以上是大佬教程为你收集整理的如何根据需要使用grunt-contrib-watch和grunt-contrib-coffee来编译CoffeeScript?全部内容,希望文章能够帮你解决如何根据需要使用grunt-contrib-watch和grunt-contrib-coffee来编译CoffeeScript?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。