刚开始学pug的时候有点不明白,然后各种搜索,后来才知道pug就是jade,原名叫jade,现在更名为pug而已。可能刚改名没有多久吧,搜pug资料很少。我也刚开始学习,希望对大家会有帮助。
1、首先要通过node.js的npm来安装pug,直接在cmd里面输入npm install -g pug 前提是你安装了node和npm (网上安装教程很多,这里就不赘述了),还需要安装cli npm install -g pug-cli ,不然会出现pug not found。 -g表示全局安装
2、写一个test.pug文件,在cmd里进入test.pug的目录下,输入pug test.pug 回车即可出现rendered test.html。输入pug -P -w test.pug比较好,因为输出的html格式会好看,并且是被监听的,修改test.pug的时候,只要保存,html会及时更新。
test.pug简单代码如下:
doctype html
head
meta(charset='utf-8')
title First file of pug
body
h1 This is my first pug
div
.div1
p that some content in here
i point
编译成html之后代码如下:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>First file of pug</title>
</head>
<body>
<h1>This is my first pug</h1>
<div>
<div class="div1"> </div>
<p>that some content in here<i>point</i></p>
</div>
</body>