我想在我保存的单个文件上运行咖啡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
我正在尝试创建一个繁琐的任务,将跨多个文件的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文件.我一直在调整这个配置,但我无法做到这一点.请帮忙.
我正在尝试编写一个grunt任务,使用grunt将许多.coffee文件编译为相应的.js文件和.map文件.我有咕噜咕噜的咖啡插件,但有一些问题:
请帮助解决这些问题:
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)