pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.7k stars 1.95k forks source link

[q] Pug in inline-template for angular2? #2406

Open psi-4ward opened 8 years ago

psi-4ward commented 8 years ago

Hi there, I'm using webpack for my current Angular2 play. Can i inline pug in my components without using require() ?

Like:

@Component({
  template: __pug(`h1 this has to be compiled at build time`)
...
})

instead of require('myc.jade')

HerringtonDarkholme commented 8 years ago

This should be consulted with Angular's team. Whilst implementing a TemplateCompiler in Angular2 may use pug's package.

ForbesLindesay commented 8 years ago

We support this for react-pug via a Babel plugin. We could do the same for regular pug.

KiaraGrouwstra commented 8 years ago

@psi-4ward: Angular 2 just expects an expression that evaluates to a html string. So if Pug can convert it to HTML, then yes, that's fine.

westonganger commented 8 years ago

+1 Has anyone figured out a way to do this yet?

KiaraGrouwstra commented 8 years ago

@westonganger: you'll find how to use Pug here, this is no different:

let pug = require('pug');

@Component({
  template: pug.render('p hi'),
})
mihilion commented 2 weeks ago

Angular team does not care about pug, and now they are encouraging people to use single file components with inline templates, rather than specifying templates in separate files. Any chances that pug team/community will come up with a solution allowing to easily use pug inside inline templates? Using require in Angular is discouraged, so I was hoping for a better method to do it than the one shown above. I know that this topic is old, but this is something I would actually use all the time. Are there really so few people wanting to use pug with Angular, that this is a niche problem?