npx parcel index.html
The page should display "It works!" using the pre-compiled pug file and should also print "hello world" in the console
Nothing happens. Not even console.log. (Commenting out the .pug require fixes the console.log)
In PugAsset
detect if the template is being required from a js file and if so call pug.compileClient
instead of pug.compile
and return compiled + ';module.exports=template;'
as well as set type = 'js'
Instead of not doing anything/confusing me I expect require('./main.pug')
to return a pre-compiled pug template function.
Assets:
parcel-pug-not-working.tar.gz
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.9.7
| Node | v10.8.0
| npm/Yarn | 6.2.0
| Operating System | Ubuntu 16.04 amd64
This is not a bug, Pug resolves into html, so it should return the html in the next version as that feature has just been added.
Not sure what you mean with the js and templates and such, if that's something pug specific and you do not mean html than this is a feature request.
Otherwise this issue should be closed due to already being implemented.
Currently the built-in pug plugin only resolves to static HTML. I need a way of using a compiled version that can dynamically render the page.
I have implemented the feature I meant here: https://github.com/mkg20001/parcel-plugin-pug-client/blob/master/PugAsset.js although this one dosen't dynamically do both js and html output, only js.
This is how it gets used: https://github.com/mkg20001/apkmirror2fdroid/blob/fbff5fd5e40f6d93d870ebd0a2d630a48bde6949/public/main.js#L62-L65
Not sure what you mean with the js and templates and such
This is documented here https://pugjs.org/api/reference.html#pugcompileclientsource-options
How is it possible for someone to miss the point of templates this hard?
Any progress on making this available upstream? Is it even possible right now to make it work this way (so it's still possible to call parcel index.pug
and use require('./some-other-file.pug')
inside the JS at the same time)
This is the one issue I currently having with parcel...
importing a pug file into a js source should provide the compiled template function, rather than the complete rendered template.
This makes pug templates actually usable in Ajax code that renders dynamic data into the page.
In short, this should be possible:
import template from './mytemplate.pug'
document.getElementById('foo').innerHTML = template(somedata);
Are there any plans to include this feature?
Most helpful comment
This is the one issue I currently having with parcel...
importing a pug file into a js source should provide the compiled template function, rather than the complete rendered template.
This makes pug templates actually usable in Ajax code that renders dynamic data into the page.
In short, this should be possible:
Are there any plans to include this feature?