coffeescriptgruntjsgrunt-contrib-watchgrunt-contrib-coffee

How to set up gruntfile so compiled files go on same directory as their source


I'm working on a really old project that used Grunt 0.3 and Coffee, and I need to update it to newer versions of both, but I'm not particularly familiar to Grunt. Previously, Grunt would compile the .js files to the exact same folder and name of source .coffee files, and I need to keep it that way. However, I'm having trouble configuring the task. This is what I have right now:

coffee: {
  options: {
  bare: true,
  sourceMap: true,
  expand: true,
  flatten: false,
  cwd: '.',
  src: ['**/*.coffee'],
  dest: '.',
  ext: ".js"
  }
}  

This is the message I get:

C:\projetos\sesc-bertioga\bertioga-server\src\main\webapp (newGrunt -> origin) (sesc-bertioga@1.0.0)
λ grunt watch
Running "watch" task
Waiting...
>> File "public\javascript\app\views\solicitacao_grupo\tripulacao_view.coffee" changed.
>> No "coffee" targets found.
Warning: Task "coffee" failed. Use --force to continue.

I absolutely can not change the output place, the new files must be on the same directory as the original ones. Do you have any ideas?


Solution

  • So after a bit of tinkering, a friend of mine came up with this, in case anyone is having a similar problem!

    coffee: {
          files: {
            expand: true,
            cwd: 'public/javascript/app',
            src: ['**/*.coffee'],
            dest: 'public/javascript/app/',
            ext: '.js',
            rename: (dest, src) => {
              return (dest + src.replace('coffee', 'js'))
            }
          },
          options: {
            bare: false,
            sourceMap: false,
            flatten: false,
            app: {
              src: ['public/javascript/app/**/*.coffee'],
            }
          }
        }  
    

    Thanks anyway =)