How can express and jade does not compress html?
Asked Answered
S

5

14

I using express and jade, but when I debug I doesn't want jade compress my html, are there any way to pass an option jade globally and make it does not compress html.

Saphena answered 3/11, 2011 at 8:9 Comment(2)
do you mean that you want the jade template to show when you view the source of the page?Hipbone
He means he wants to turn off compression during compilation for the jade middleware. I believe. At least that's what I want.Microscopic
A
14

In the time since this answer was written an option has been added to control this behaviour.

app.locals.pretty = true;

At the moment, no. This feature has been discussed here:

https://github.com/visionmedia/jade/pull/205

The html doesn't actually get compressed or minified by default, though. It's just not formatted nicely. The simplest way I've found to make it human-readable is to use Chrome's dev tools, which give you a nice foldable representation of the source.

Arachne answered 4/11, 2011 at 1:47 Comment(3)
I asked TJ. use app.set('view options', {pretty: true});Eulogy
@guilin桂林 This should not be the accepted answer. The answer with the most upvotes is the correct oneMicroscopic
Thanks, @light24bulbs. The answer was wrong. I've updated it to be more correct.Arachne
K
28

If you use Express 3.x, you can control compression via app.locals.pretty. I usually enable it while development:

app.configure('development', function () {
    app.locals.pretty = true;
});
Kress answered 19/2, 2013 at 19:20 Comment(0)
A
14

In the time since this answer was written an option has been added to control this behaviour.

app.locals.pretty = true;

At the moment, no. This feature has been discussed here:

https://github.com/visionmedia/jade/pull/205

The html doesn't actually get compressed or minified by default, though. It's just not formatted nicely. The simplest way I've found to make it human-readable is to use Chrome's dev tools, which give you a nice foldable representation of the source.

Arachne answered 4/11, 2011 at 1:47 Comment(3)
I asked TJ. use app.set('view options', {pretty: true});Eulogy
@guilin桂林 This should not be the accepted answer. The answer with the most upvotes is the correct oneMicroscopic
Thanks, @light24bulbs. The answer was wrong. I've updated it to be more correct.Arachne
H
1

You can use Jade Comments to annotate your code for viewing in the browser.

//h1
h1 Some Title
//p
p some content

will output

<!--h1-->
<h1>Some Title</h1>
<!--p-->
<p>some content</p>

The template is already compiled once it leaves the server, so if you wanted to view the template in the browser you would have to write a plugin that de-compiles html to jade and than display the decompiled version.

Hipbone answered 3/11, 2011 at 19:14 Comment(2)
Shouldn't those HTML comments be <!-- --> ?Corpora
@Corpora afaik, jade outputs HTML comments for // and completely ignores /// comments.Kress
B
1

Huh, new to nodejs so maybe missing something here; but in app.js adding app.set('view options', {pretty: true}); was ineffectual (using express 3.0.3).

..doesn't appear to be supported? did find a workaround, e.g. on a per route basis:

exports.index = function(req, res){
  res.render('index', {
    [... other stuff ...]
    pretty: true
  });
};
Banneret answered 25/11, 2012 at 22:7 Comment(1)
If you look at Andy's answer, it's pretty much the same. (res.render('index', { /* view.locals */ })). If you set it on the app.locals, it extends to all your res.render() calls. Some documentation on how app/view locals work.Slavery
S
0

For whom using pug-cli, you need to add --pretty in cmd(terminal). Like the following,

pug --pretty -w -o dist/html/ assets/pug/index.pug
Secularism answered 17/4, 2021 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.