国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
詳解Grunt插件之LiveReload實(shí)現(xiàn)頁(yè)面自動(dòng)刷新(兩種方案),gruntlivereload
Home php教程 php手冊(cè) 詳解Grunt插件之LiveReload實(shí)現(xiàn)頁(yè)面自動(dòng)刷新(兩種方案),gruntlivereload

詳解Grunt插件之LiveReload實(shí)現(xiàn)頁(yè)面自動(dòng)刷新(兩種方案),gruntlivereload

Jun 13, 2016 am 08:56 AM
grunt Auto Refresh

詳解Grunt插件之LiveReload實(shí)現(xiàn)頁(yè)面自動(dòng)刷新(兩種方案),gruntlivereload

方案一:grunt-livereload + Chrome Plug-in

優(yōu)點(diǎn):安裝、配置簡(jiǎn)單方便。
缺點(diǎn):需要配合指定的瀏覽器插件(Firefox也有相關(guān)插件,IE么你懂的)。

1. 需要安裝2個(gè)插接件:grunt-contrib-watch、connect-livereload

執(zhí)行命令:

復(fù)制代碼 代碼如下:
npm install --save-dev grunt-contrib-watch connect-livereload

2. 安裝瀏覽器插件:Chrome LiveReload

3. 配置一個(gè)Web服務(wù)器(IIS/Apache),LiveReload需要在本地服務(wù)器環(huán)境下運(yùn)行(對(duì)file:///文件路徑支持并不是很好)。

4. 修改Gruntfile.js文件:

module.exports = function(grunt) {
 // 項(xiàng)目配置(任務(wù)配置)
 grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  watch: {
   client: {
    files: ['*.html', 'css/*', 'js/*', 'images/**/*'],
    options: {
     livereload: true
    }
   }
  }
 });
 // 加載插件
 grunt.loadNpmTasks('grunt-contrib-watch');
 // 自定義任務(wù)
 grunt.registerTask('live', ['watch']);
};

5. 執(zhí)行:grunt live

看到如下提示,說(shuō)明已經(jīng)開(kāi)始監(jiān)聽(tīng)任務(wù):

復(fù)制代碼 代碼如下:
Running "watch" task
Waiting...

6. 打開(kāi)我們的頁(yè)面,例如:http://localhost/

7. 再點(diǎn)擊Chrome LiveReload插件的ICON,此時(shí)ICON圓圈中心的小圓點(diǎn)變成實(shí)心的,說(shuō)明插件執(zhí)行成功。此時(shí)你改下網(wǎng)站文件看看,是不是實(shí)時(shí)更新了?

方案二:grunt-contrib-watch + grunt-contrib-connect + grunt-livereload

優(yōu)點(diǎn):自動(dòng)搭建靜態(tài)文件服務(wù)器,不需在自己電腦上搭建Web服務(wù)器。
   不需要瀏覽器插件的支持(不現(xiàn)定于某個(gè)瀏覽器)。
    不需要給網(wǎng)頁(yè)手動(dòng)添加livereload.js。
缺點(diǎn):對(duì)于剛接觸的人,配置略顯復(fù)雜。

1. 安裝我們所需要的3個(gè)插件:grunt-contrib-watch、grunt-contrib-connect、connect-livereload

執(zhí)行命令:

復(fù)制代碼 代碼如下:
npm install --save-dev grunt-contrib-watch grunt-contrib-connect connect-livereload

2. 修改Gruntfile.js文件:

module.exports = function(grunt) {
 // LiveReload的默認(rèn)端口號(hào),你也可以改成你想要的端口號(hào)
 var lrPort = 35729;
 // 使用connect-livereload模塊,生成一個(gè)與LiveReload腳本
 // <script src="http://127.0.0.1:35729/livereload.js&#63;snipver=1" type="text/javascript"></script>
 var lrSnippet = require('connect-livereload')({ port: lrPort });
 // 使用 middleware(中間件),就必須關(guān)閉 LiveReload 的瀏覽器插件
 var lrMiddleware = function(connect, options) {
  return [
   // 把腳本,注入到靜態(tài)文件中
   lrSnippet,
   // 靜態(tài)文件服務(wù)器的路徑
   connect.static(options.base[0]),
   // 啟用目錄瀏覽(相當(dāng)于IIS中的目錄瀏覽)
   connect.directory(options.base[0])
  ];
 };
 // 項(xiàng)目配置(任務(wù)配置)
 grunt.initConfig({
  // 讀取我們的項(xiàng)目配置并存儲(chǔ)到pkg屬性中
  pkg: grunt.file.readJSON('package.json'),
  // 通過(guò)connect任務(wù),創(chuàng)建一個(gè)靜態(tài)服務(wù)器
  connect: {
   options: {
    // 服務(wù)器端口號(hào)
    port: 8000,
    // 服務(wù)器地址(可以使用主機(jī)名localhost,也能使用IP)
    hostname: 'localhost',
    // 物理路徑(默認(rèn)為. 即根目錄) 注:使用'.'或'..'為路徑的時(shí),可能會(huì)返回403 Forbidden. 此時(shí)將該值改為相對(duì)路徑 如:/grunt/reloard。
    base: '.'
   },
   livereload: {
    options: {
     // 通過(guò)LiveReload腳本,讓頁(yè)面重新加載。
     middleware: lrMiddleware
    }
   }
  },
  // 通過(guò)watch任務(wù),來(lái)監(jiān)聽(tīng)文件是否有更改
  watch: {
   client: {
    // 我們不需要配置額外的任務(wù),watch任務(wù)已經(jīng)內(nèi)建LiveReload瀏覽器刷新的代碼片段。
    options: {
     livereload: lrPort
    },
    // '**' 表示包含所有的子目錄
    // '*' 表示包含所有的文件
    files: ['*.html', 'css/*', 'js/*', 'images/**/*']
   }
  }
 }); // grunt.initConfig配置完畢
 // 加載插件
 grunt.loadNpmTasks('grunt-contrib-connect');
 grunt.loadNpmTasks('grunt-contrib-watch');
 // 自定義任務(wù)
 grunt.registerTask('live', ['connect', 'watch']);
};

5. 執(zhí)行:grunt live

看到如下提示,說(shuō)明Web服務(wù)器搭建完成,并且開(kāi)始監(jiān)聽(tīng)任務(wù):
復(fù)制代碼 代碼如下:
Running "connect:livereload" (connect) task
Started connect web server on 127.0.0.1:8000.

Running "watch" task
Waiting...

注:執(zhí)行該命令前,如果你有安裝過(guò)LiveReload的瀏覽器插件,必須關(guān)閉。

6. 打開(kāi)我們的頁(yè)面,例如:http://localhost:8000/http://127.0.0.1:8000/
注:這里所打開(kāi)的本地服務(wù)器地址,是我們剛才通過(guò)connect所搭建的靜態(tài)文件服務(wù)器地址,而不是之前你用IIS或Apache自己搭建Web服務(wù)器地址。

以上就是本文詳解Grunt插件之LiveReload實(shí)現(xiàn)頁(yè)面自動(dòng)刷新(兩種方案),希望大家喜歡。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up web page automatic refresh How to set up web page automatic refresh Oct 26, 2023 am 10:52 AM

To set the automatic refresh of a web page, you can use the HTML "meta" tag, the JavaScript "setTimeout" function, the "setInterval" function or the HTTP "Refresh" header. Detailed introduction: 1. Use the "meta" tag of HTML. In the "<head>" tag of the HTML document, you can use the "meta" tag to set the automatic refresh of the web page; 2. The "setTimeout" function of JavaScript, etc.

Python script automatically refreshes Excel spreadsheet Python script automatically refreshes Excel spreadsheet Sep 09, 2023 pm 06:21 PM

Python and Excel are two powerful tools that when combined can open up a world of automation. Python has versatile libraries and user-friendly syntax that enable us to write scripts to perform various tasks efficiently. Excel, on the other hand, is a widely used spreadsheet program that provides a familiar interface for data analysis and manipulation. In this tutorial, we will explore how to leverage Python to automate the process of refreshing Excel spreadsheets, saving us time and effort. Do you find yourself spending valuable time manually refreshing your Excel spreadsheet with updated data? This is a repetitive and time-consuming task that can really kill productivity. In this article we will guide you through using Py

Using Python and WebDriver to automatically refresh web pages Using Python and WebDriver to automatically refresh web pages Jul 08, 2023 pm 01:46 PM

Using Python and WebDriver to implement automatic web page refresh Introduction: In daily web browsing, we often encounter scenarios that require frequent web page refreshes, such as monitoring real-time data, automatically refreshing dynamic pages, etc. Manually refreshing the web page will waste a lot of time and energy, so we can use Python and WebDriver to implement the function of automatically refreshing the web page and improve our work efficiency. 1. Installation and configuration environment Before starting, we need to install and configure the corresponding environment. Install Python

How to solve the problem of automatic refresh of Win10 desktop? How to solve the problem of automatic refresh of Win10 desktop? Jun 30, 2023 pm 11:13 PM

How to solve the problem that the Win10 system desktop frequently refreshes automatically? We all use computers for study and entertainment in our daily life, and there are many files and applications we need on the desktop. However, recently when some friends are using win10, the desktop keeps refreshing automatically. If you don't know how to solve it, the editor below has compiled a guide to solving the problem of frequent automatic refresh of the Win10 system desktop. If you are interested, follow the editor to read below! Solution guide for Win10 system desktop frequently refreshing automatically 1. Right-click the "Start" menu and select "Task Manager", as shown in the figure. 2. In the "Task Manager" interface, find "Windows Explorer" in the process, as shown in the figure. 3. Right-click it and select in the interface that appears.

What should I do if my win11 desktop frequently refreshes automatically? What should I do if my win11 desktop frequently refreshes automatically? Jun 29, 2023 pm 02:56 PM

What should I do if my win11 desktop frequently refreshes automatically? The win11 system is the latest Windows system launched by Microsoft. It is built with the latest technology and can provide you with the latest high-quality services, but at the same time, there are also some new types of problems. Recently, some friends reported that the desktop often refreshes after win11 is updated. This is most likely because there are some problems with the system. So, how should we solve this problem? Below, the editor will bring you a solution to the frequent automatic refresh of the Win11 desktop. The win11 desktop often automatically refreshes the solution. Method 1: Uninstall updates 1. First, we use the keyboard "ctrl+shift+esc" key combination to open the task manager. 2. After opening, click

Python implements automatic page refresh and scheduled task function analysis for headless browser collection applications Python implements automatic page refresh and scheduled task function analysis for headless browser collection applications Aug 08, 2023 am 08:13 AM

Python implements automatic page refresh and scheduled task function analysis for headless browser collection applications. With the rapid development of the network and the popularization of applications, the collection of web page data has become more and more important. The headless browser is one of the effective tools for collecting web page data. This article will introduce how to use Python to implement the automatic page refresh and scheduled task functions of a headless browser. The headless browser adopts a browser operation mode without a graphical interface, which can simulate human operation behavior in an automated way, thereby enabling the user to access web pages, click buttons, and fill in information.

How to set up QQ Browser to automatically refresh web pages How to set up QQ Browser to automatically refresh web pages Jan 29, 2024 pm 03:36 PM

How to set QQ Browser to automatically refresh the current web page? When we use QQ browser to buy products, we can turn on the operation of automatically refreshing the current web page. When using QQ Browser, sometimes we need to snap up purchases at designated locations during shopping festivals. In this case, we need to set up automatic refresh of the current web page, but many friends don’t know how to set it up. The editor has compiled the automatic settings for Tencent Browser below. Refresh the current web page operation. If you don’t know how, follow me and take a look below! Tencent browser settings automatically refresh the current web page operation. Use the mobile QQ secure browser to open the web page that needs to be refreshed automatically, and click the bottom menu icon (composed of three horizontal lines), as shown in the figure. 2. At this time, the menu window of the mobile QQ green browser will pop up below. Find and click in the window.

How to solve the problem of automatic refresh of Win11 desktop How to solve the problem of automatic refresh of Win11 desktop Jan 09, 2024 am 09:57 AM

Although the Win11 system has been launched for a long time, we still encounter many problems during use. For example, some friends often encounter the situation where the screen and desktop keep refreshing automatically during use. At this time, we need to How to solve it? Let’s take a look at the solution with the editor below. Solution to automatic refresh of Win11 desktop 1. First, we use the keyboard "ctrl+shift+esc" key combination to open the Task Manager. 2. After opening, click "File" in the upper left corner and select "Run New Task". 3. Then check the option "Create this task with system administrative rights".

See all articles