suchen

Heim  >  Fragen und Antworten  >  Hauptteil

node.js - 菜鸟关于JADE的问题

请问一下jade模版怎么运行?在编译器里写好之后怎么运行测试?第一次用nodeJS,第一次用jade,不太理解

PHPzPHPz2865 Tage vor592

Antworte allen(1)Ich werde antworten

  • 高洛峰

    高洛峰2017-04-17 13:59:29

    你说的写好应该是“编辑器”吧?^^,能在“编译器”里写好代码的,想必应该很屌!

    而且现在好像也不叫jade,改叫:pug了。

    打开一个命令行,先安装pug命令工具:

    npm install pug-cli -g

    如果是非windows的操作系统,再前面加sudo

    然后写一个pug的模板:

    test.pug

    doctype html
    html(lang="en")
      head
        title= pageTitle
        script(type='text/javascript').
          if (foo) bar(1 + 5)
      body
        h1 Pug - node template engine
        #container.col
          if youAreUsingPug
            p You are amazing
          else
            p Get on it!
          p.
            Pug is a terse and simple templating language with a
            strong focus on performance and powerful features.

    然后在命令行里,使用pug命令将其转义成真正的html:

    pug -P test.pug

    然后就自动生成了这个样子的html:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title></title>
        <script type="text/javascript">if (foo) bar(1 + 5)</script>
      </head>
      <body>
        <h1>Pug - node template engine</h1>
        <p class="col" id="container">
          <p>Get on it!</p>
          <p>
            Pug is a terse and simple templating language with a
            strong focus on performance and powerful features.
          </p>
        </p>
      </body>
    </html>

    html该怎么用,不用我教吧?

    当然我介绍的这是小白入门。高阶用法,都是都是集成在其他项目构建工具里的。慢慢来吧,一口气肯定吃不成个胖子

    Antwort
    0
  • StornierenAntwort