stephenhutchings / jade-static-brunch

Adds Jade static support to Brunch
2 stars 2 forks source link

how to avoid partials polluting the production build? #9

Open webakimbo opened 8 years ago

webakimbo commented 8 years ago

Not sure if this is a bug or a feature request, but getting the same error as with this closed issue.

Assume I have two files, index.jade and _some_partial.jade, in /app/markup.

My config looks like this:

jadeStatic: {
  formatPath: function(path){ return path.match(/^app(\/|\\)markup(\/|\\)(.+)\.jade$/)[3]; },
  extension: '.html',
  pretty: true
}

And in index.jade:

include ./_some_partial.jade

The plugin compiles both to html files in /public... but then the production build is polluted with a partial file (/public/_some_partial.html) that shouldn't be served by itself.

My expectation was that jade would perform the includes first, then compile to a single static file (/public/index.html) that gets served. If I exclude partials from formatPath:

...
  formatPath: function(path){ return path.match(/^app(\/|\\)markup(\/|\\)([^_].+)\.jade$/)[3]; },
...

...I get the "cannot read property '3' of null" error, and the build fails.

bkuri commented 8 years ago

I'd really appreciate an answer to this as well. I've tried different folder structures and regexes, to no avail. TIA

stephenhutchings commented 8 years ago

The pollution of partial files can be fixed within your brunch config. For example, you configuration might look like this...

exports.config =
  ...
  conventions:
    ignored: [
      /[\\/]_/
      /^app\/markup\/partials/
    ]
  ...

...which tells Brunch not to compile any files starting with underscore or in the partials folder. This will probably solve your second issue with the error of path formatting, in which the regular expression returns no match, and therefore the attempt to read the matches at position 3 throws an error. A formatPath method that is less likely to fail would be a simpler string replace, as in...

 formatPath: (path) -> path.replace("app/markup/", "")