搜尋

首頁  >  問答  >  主體

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

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

PHPzPHPz2936 天前614

全部回覆(1)我來回復

  • 高洛峰

    高洛峰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該怎麼用,不用我教吧?

    當然我介紹的這是小白入門。高階用法,都是都是整合在其他專案建置工具裡的。慢慢來吧,一口氣一定吃不成個胖子

    回覆
    0
  • 取消回覆