ridermansb
ridermansb

Reputation: 11069

Compile to `.js` maintaining the same folder structure

In my app (Asp.net mvc) I have the following folder structure:

Foder structure

Scripts folder contains all .js and .coffee files. Inside the folder Controllers I have a folder for each controller.

I need that whenever a .coffee file changed, a new file .js is created in the same folder with the same name.

module.exports = (grunt) -> 
    # Configurações
    grunt.initConfig
        coffee:
            compile:
                options:
                    basePath: 'Scripts'
                    preserve_dirs: true
                files: 'Scripts/*.js': 'Scripts/**/*.coffee'

    # Plugins
    grunt.loadNpmTasks 'grunt-contrib-coffee'

When I run grunt: grunt coffee the following error occurs:

Unable to write "Scripts/*.js" file (Error code: ENOENT). Use --force to continue

Erro grunt

Upvotes: 3

Views: 2175

Answers (1)

hereandnow78
hereandnow78

Reputation: 14434

use it that way:

coffee:
  compile:
    files: [
      expand: true
      cwd: "./Scripts"
      src: ["**/*.coffee"]
      dest: "./Scripts"
      ext: ".js"       
    ]

read more about it here: http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically

Upvotes: 11

Related Questions