Parcel: Nunjucks Support

Created on 22 Mar 2018  ยท  9Comments  ยท  Source: parcel-bundler/parcel

Is there a way to get parcel to process non HTML entry files?. I use Nunjucks templates, these are ignored by parcel. Parcel works however when I rename the file to HTML

This works
"build": "parcel build ./views/layout.html --out-dir public/assets"

This does'nt
"build": "parcel build ./views/layout.njk --out-dir public/assets"

Thanks

Help Wanted Feature

All 9 comments

It would work if nunjucks is supported by parcel, I guess a plugin for it would be the proper approach?

@DeMoorJasper, You misunderstood me, I would like Parcel to compile the CSS and JS assets defined in the Nunjucks template not compile the Nunjuck Template itself

I just looked into, and it looks like nunjucks has two ways to use it...
you can leave the templates in the HTML and evaluate them on runtime, or
precompile ahead of time.

If you plan to evaluate them on runtime, then I suggest just renaming the
file to .html and using Parcel as normal. However, if you need Parcel to
precompile the templates, as Jasper said, your gonna need a plugin
On Thu, Mar 22, 2018 at 12:47 PM Jasper De Moor notifications@github.com
wrote:

It would work if nunjucks is supported by parcel, I guess a plugin for it
would be the proper approach?

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/parcel-bundler/parcel/issues/1044#issuecomment-375376184,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGck4iJmiuK0H8KfUY_Zvl8vlz6_yyr1ks5tg9WKgaJpZM4S3Zxn
.

We could add it as a known html extension, but I'm not sure if that's supposed to be the case. If i'm mistaken this could be an easy fix.
What i simply meant is the extension isn't known to parcel (so it doesn't know how to process it)

@DeMoorJasper I was thinking the same thing. But, that could get in the way if someone decides to make a plugin that _doesn't_ treat them as HTML.

In the future if someone makes a plugin that precompiles files with the njk file extension.

@davidnagli The plugin would overwrite it, not cause any issues. So it might be a pretty good idea, although i'm not sure never used nunjucks

@DeMoorJasper Oh ya you're right ๐Ÿ‘ I didn't realize that we register extensions in the Bundler's constructor, with would mean that plugins run after, which allows them to override.

There seems to be a plugin for this https://github.com/devmattrick/parcel-plugin-nunjucks, I don't know if it works

I would like Parcel to compile the CSS and JS assets defined in the Nunjucks template not [just] compile the Nunjuck Template itself

As @danielpza mentioned, this works with the nunjucks plugin: https://github.com/chocolateboy/parcel-plugin-nunjucks#assettype

Was this page helpful?
0 / 5 - 0 ratings