如何提供呈现的Jade页面,就像它们是Node Express中的静态HTML页面一样? [英] How to serve rendered Jade pages as if they were static HTML pages in Node Express?

查看:139
本文介绍了如何提供呈现的Jade页面,就像它们是Node Express中的静态HTML页面一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,您在这样的路线中呈现玉页:

  app.get('/ page',function req,res,next){
res.render('page.jade');
});

但是我想为所有的Jade页面(自动呈现)提供服务,就像提供静态HTML

  app.use(express.static('public'))
pre>

有没有办法为Jade做类似的事情?

解决方案

p> https://github.com/runk/connect-jade-static


用法



假设项目的以下结构:

  / views 
/ partials
/file.jade

让我们从 / views / partials web accessable:

  var jadeStatic = require('connect-jade-static'); 

app = express();
app.configure(function(){
app.use(jadeStatic({
baseDir:path.join(__ dirname,'/ views / partials'),
baseUrl:' / partials',
jade:{pretty:true}
}));
});

现在,如果您启动Web服务器并请求 / views / partials / file.html 在浏览器中
应该可以看到编译的玉模板。



Usually you render a Jade page in a route like this:

app.get('/page', function(req, res, next){
    res.render('page.jade');
});

But I want to serve all Jade pages (automatically rendered), just like how one would serve static HTML

app.use(express.static('public'))

Is there a way to do something similar for Jade?

解决方案

https://github.com/runk/connect-jade-static

Usage

Assume the following structure of your project:

/views
  /partials
    /file.jade

Let's make jade files from /views/partials web accessable:

var jadeStatic = require('connect-jade-static');

app = express();
app.configure(function() {
  app.use(jadeStatic({
    baseDir: path.join(__dirname, '/views/partials'),
    baseUrl: '/partials',
    jade: { pretty: true }
  }));
});

Now, if you start your web server and request /views/partials/file.html in browser you should be able see the compiled jade template.

这篇关于如何提供呈现的Jade页面,就像它们是Node Express中的静态HTML页面一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆