gruntjs/grunt-contrib-handlebars

Dynamic file mapping not working properly

Closed this issue · 3 comments

I'm trying to compile as in Grunt Docs, using dynamic file mapping, but the result is somewhat strange.

        # Gruntfile.coffee
        handlebars:
            compile:
                options:
                    namespace: "App.templates"

                files:[
                    expand: true
                    cwd: 'src/'
                    src: ['**/*.hbs']
                    dest: 'dest/templates.js'
                ]

A few variations were used there, but my conclusion was that grunt-contrib-handlebars is not handling this syntax of file mapping properly or I'm very confused about how it works.

Any lights?

Expand mode is for when you want to map files 1-1. Aka, you want one template file out for each template file in. You don't need that here--you should be good to go like this:

        # Gruntfile.coffee
        handlebars:
            compile:
                src: ['src/**/*.hbs']
                dest: 'dest/templates.js'
                options:
                    namespace: "App.templates"

Thank you!

And it is quite there. Is there a way to cwd this? I dont want the src/ part in my compiled files.

You really ought to be able to do this, but it isn't supported in Grunt yet. We're working on it here, though.

For now, you can use processName:
https://github.com/gruntjs/grunt-contrib-handlebars#processname