Spearfisher
Spearfisher

Reputation: 8773

Keep folders structure while compiling with grunt

I am using grunt to compile some jade files into html ones.

My files look like this:

index.jade
|--partials/
           view1.jade
           view2.jade

I use grunt-contrib-jade to compile them with the following code:

    jade: {
  compile: {
    options: {
      data: {
        debug: true
      }
    },
    files:
      [{
        expand: true,
        cwd: 'src/',
        src: ['*.jade', '*/*.jade'],
        dest: 'dist/views',
        ext: '.html',
      }]
  }
},

It works fine, all the file are compiled however it breaks the files structure putting all the files in dist/views

Is there a way to keep the structure, i.e. get something like this?

dist/views
|--------- index.html
|---------/partials/
                   / all other files

Many thanks

Upvotes: 0

Views: 128

Answers (1)

Evan Davis
Evan Davis

Reputation: 36592

Use the flatten property:

files:
  [{
    expand: true,
    flatten: false, // <---- don't flatten the folder structure
    cwd: 'src/',
    src: ['**/*.jade'], // <---- also update your glob to grab all the .jade files at once
    dest: 'dist/views',
    ext: '.html',
  }]

Upvotes: 2

Related Questions