溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

grunt使用watch和livereload的Gruntfile.js的配置

發(fā)布時(shí)間:2020-06-29 11:07:29 來(lái)源:網(wǎng)絡(luò) 閱讀:349 作者:張濤澤 欄目:網(wǎng)絡(luò)安全

 周末在家看angularJS, 用grunt的livereload的自動(dòng)刷新, 搞了大半天, 現(xiàn)在把配置貼出來(lái), 免得以后忘記了, 只要按照配置一步步弄是沒(méi)有問(wèn)題的;

  開(kāi)始的準(zhǔn)備的環(huán)境安裝是:

 ?。?):nodeJS,去官方網(wǎng)站下載(href); 

  (2):然后把nodeJS加到全局的環(huán)境變量里面去(nodeJS安裝好了就能用npm這個(gè)命令了),參考(href);

 ?。?):執(zhí)行npm install grunt -g 和 npm install -g grunt-cli,一個(gè)是安裝服務(wù)端的gurnt一個(gè)是客戶(hù)端的grunt(反正都安裝就好了),參考(href)

  

  第一步:新建一個(gè)叫做Gruntfile.js的js文件

運(yùn)行下面代碼

grunt使用watch和livereload的Gruntfile.js的配置

module.exports = 'package.json'9000'127.0.0.1', 
                livereload: 35729  , "html"                          35729 '**/*''default',["connect","watch"'grunt-contrib-watch''grunt-contrib-connect'

grunt使用watch和livereload的Gruntfile.js的配置

  

  2:新建一個(gè)package.json的文件, 直接在cmd(命令行)下執(zhí)行npm install即可把所有的node_module自動(dòng)下載下來(lái);

運(yùn)行下面代碼

grunt使用watch和livereload的Gruntfile.js的配置

{    "name": "nono",    "version": "0.0.0",    "description": "for watch",    "main": "Gruntfile.js",    "dependencies": {    "grunt": "~0.4.5",        "express": "~3.15.2",        "grunt-contrib-connect": "~0.6.0",        "grunt-contrib-watch": "~0.5.3"},    "devDependencies": {},    "scripts": {    "test": "echo \"Error: no test specified\" && exit 1"},    "repository": {    "type": "git",        "url": "sqqihao.github.com"},    "keywords": [    "nono"],    "author": "nono",    "license": "__MIT__"}

grunt使用watch和livereload的Gruntfile.js的配置

  

  好了, 現(xiàn)在在當(dāng)前目錄下執(zhí)行g(shù)runt, grunt會(huì)自動(dòng)監(jiān)控所有文件的變化, 當(dāng)你的文件一旦發(fā)生改變的,  你通過(guò)127.0.0.1打開(kāi)的所有html格式文件都會(huì)自動(dòng)刷新;新航道雅思

;


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI