標籤:
比如把coffee檔案寫在coffee/controller/檔案夾下,建立js/controller檔案夾,使用grunt運行項目,將自動編譯coffee到相應的js檔案夾下。
module.exports = function(grunt) { // 項目配置資訊. grunt.initConfig({ pkg: grunt.file.readJSON(‘package.json‘), jshint: { options : { jshintrc: ‘.jshintrc‘, // eqeqeq: true, // tradiling: true, ignores: [‘node_modules/**/*.js‘] }, all: [‘**/*.js‘] }, coffee:{ compile: { options: { sourceMap: false, bare: true }, files: [{ expand: true, cwd: "coffee/", src: ‘**/*.coffee‘, dest: ‘js/‘, ext: ‘.js‘ }] } }, watch: { coffee: { files: [‘**/*.coffee‘], tasks: [‘coffee:compile‘] // }, // js: { // files: [‘**/*.js‘], // tasks: [‘jshint‘], // options: { // livereload: true // } } }, nodemon: { dev: { script: ‘bin/www‘, options: { args: [], ignoredFiles: [], watchedExtensions: [‘js‘], watchedFolders: [‘./‘], debug: true, delayTime: 1, env: { PORT: 3000 }, cwd: __dirname } } }, concurrent: { tasks: [‘watch‘,‘nodemon‘], options: { logConcurrentOutput: true } } }); // 載入"uglify"外掛程式.. grunt.loadNpmTasks(‘grunt-contrib-watch‘); grunt.loadNpmTasks(‘grunt-contrib-coffee‘); grunt.loadNpmTasks(‘grunt-contrib-jshint‘); grunt.loadNpmTasks(‘grunt-nodemon‘); grunt.loadNpmTasks(‘grunt-concurrent‘); //grunt.loadNpmTasks(‘grunt-ssh‘); grunt.option(‘force‘, true); // 註冊預設任務. grunt.registerTask(‘default‘, [‘concurrent‘]);};
自動編譯CoffeeScript的Gruntfile.js