handlebars 安裝: html
一、npm node
二、npm install -g handlebars(後面能夠加@3.0.1版本號) npm
三、handlebars public/js/template > public/js/template.js 在相應目錄進行預編譯 windows
事先肯定你的電腦上已經安裝了node.js 函數
而後根據npm install -g handlebars 命令安裝handlebars ui
此時我碰到了一個問題: this
雖然提示handlebars安裝成功,windows+r>>>>cmd>>>>handlebars>提示'handlebars'不是內部或外部命令,也不是可運行的程序 或批處理 spa
因而我查了不少資料,發現出現該命令的可能緣由是由於麼有設置環境變量。 .net
當我在用戶環境變量中添加 C:\Program Files\nodejs\;(node.js安裝路徑),並無成功。 htm
最後終於獲得了一個解決辦法:
是這麼解決的, 環境變量增長NODE_PATH C:\Users\xxx\AppData\Roaming\npm\ 而後PATH裏最後加上%NODE_PATH%
如今終於在命令框中屬於handlebars提示了:
Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留全部權利。
C:\Users\huainanhai>handlebars
Precompile handlebar templates.
Usage: node C:\Users\huainanhai\AppData\Roaming\npm\node_modules\handlebars\bin\
handlebars [template|directory]...
Options:
-f, --output Output File
--map Source Map File
[string] [default: undefined]
-a, --amd Exports amd style (require.js)
-c, --commonjs Exports CommonJS style, path to Handlebars module
[default: null]
-h, --handlebarPath Path to handlebar.js (only valid for amd-style)
[default: ""]
-k, --known Known helpers
-o, --knownOnly Known helpers only
-m, --min Minimize output
-n, --namespace Template namespace
[default: "Handlebars.templates"]
-s, --simple Output template function only.
-r, --root Template root. Base value that will be stripped from temp
late names.
-p, --partial Compiling a partial template
-d, --data Include data when compiling
-e, --extension Template extension.
[default: "handlebars"]
-b, --bom Removes the BOM (Byte Order Mark) from the beginning of t
he templates.
-v, --version Prints the current compiler version
--help Outputs this message
到如今爲止 handlebars 算做安裝完成
C:\Users\huainanhai>handlebars -v
4.0.5
但是當我使用命令編譯template文件夾後生成了template.js文件 運行後發現提示handlebars的函數出現問題,非常頭疼,編譯出來的內容不正常,後來又展轉得知多是handlebars版本問題 須要安裝handlebars 3.0.1 版本才能夠,使用命令 npm install -g handlebars@3.0.1
C:\Users\huainanhai>handlebars -v
3.0.1
此刻再次編譯template文件 運行html頁面,頁面顯示無誤,終於完成了!
以上內容純屬原創,若有轉載,請標明出處!
本文地址:http://my.oschina.net/u/2508830/blog/536258