node.js - 菜鸟关于JADE的问题
PHPz
PHPz 2017-04-17 13:57:29
0
1
587

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

PHPz
PHPz

学习是最好的投资!

全部回覆(1)
小葫芦

你說的寫好應該是「編輯器」吧? ^^,能在「編譯器」裡寫好程式碼的,想必應該很屌!

而且現在好像也不叫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該怎麼用,不用我教吧?

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

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板