标签: grunt-contrib-coffee

如何根据需要使用grunt-contrib-watch和grunt-contrib-coffee来编译CoffeeScript?

我想在我保存的单个文件上运行咖啡lint和咖啡编译.我的项目中有数百个CoffeeScript文件,编译所有这些文件需要花费太多时间.

这是我的Gruntfile:

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', 'all'], filepath)

  grunt.loadNpmTasks 'grunt-coffeelint'
  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-watch'

  grunt.registerTask 'default', ['coffeelint', 'coffee', 'watch']
Run Code Online (Sandbox Code Playgroud)

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

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

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

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


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

Running "coffee:all" (coffee) task …
Run Code Online (Sandbox Code Playgroud)

coffeescript gruntjs grunt-contrib-watch grunt-contrib-coffee

10
推荐指数
2
解决办法
4274
查看次数

创建用于在目录和子目录中递归编译coffeescript文件的grunt任务

我正在尝试创建一个繁琐的任务,将跨多个文件的coffeescript代码编译为同名的.js文件.我有grunt coffeescript插件,我希望使用此页面上给出的"glob_to_multiple"规范:

https://www.npmjs.org/package/grunt-contrib-coffee.

 glob_to_multiple: {
    expand: true,
    flatten: true,
    cwd: 'path/to',
    src: ['*.coffee'],
    dest: 'path/to/dest/',
    ext: '.js'
  },
Run Code Online (Sandbox Code Playgroud)

但是,这个grunt任务不会将.coffee文件编译为相应名称的.js文件 - 对于目录及其子目录中的所有.coffee文件.我一直在调整这个配置,但我无法做到这一点.请帮忙.

coffeescript gruntjs grunt-contrib-coffee

4
推荐指数
1
解决办法
1037
查看次数

使用grunt编译coffeescript文件

我正在尝试编写一个grunt任务,使用grunt将许多.coffee文件编译为相应的.js文件和.map文件.我有咕噜咕噜的咖啡插件,但有一些问题:

  1. 它将所有文件编译到一个公共目标文件夹中,而不是将.js文件保存在与.coffee文件相同的文件夹中.
  2. 它将不同目录中的两个同名的.coffee文件合并到目标目录中的一个文件中.

请帮助解决这些问题:

Grunt插件:https://www.npmjs.org/package/grunt-contrib-coffee

Gruntfile.coffee:

module.exports = (grunt) ->
  grunt.initConfig(
    pkg: grunt.file.readJSON 'package.json'
    coffee:
      coffee_to_js:
        options:
          bare: true
          sourceMap: true
        expand: true
        flatten: true
        cwd: "client"
        src: ["**/*.coffee"]
        dest: 'client'
        ext: ".js"
  )

  #Load Tasks
  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.registerTask('compile', ['coffee']);

  null
Run Code Online (Sandbox Code Playgroud)

编译Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    coffee: {
      coffee_to_js: {
        options: {
          bare: true,
          sourceMap: true
        },
        expand: true,
        flatten: true,
        cwd: "client",
        src: ["**/*.coffee"],
        dest: 'client',
        ext: ".js"
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-coffee');
  grunt.registerTask('compile', …
Run Code Online (Sandbox Code Playgroud)

coffeescript gruntjs grunt-contrib-coffee

2
推荐指数
1
解决办法
4817
查看次数