grunt 는 watch 와 livereload 의 Gruntfile. js 설정 을 사용 합 니 다.

5072 단어 grunt
주말 에 집에 서 angularJS 를 보고 grunt 의 livereload 의 자동 새로 고침 으로 반나절 을 했 습 니 다. 지금 은 설정 을 붙 였 습 니 다. 나중에 잊 지 않도록 설정 에 따라 한 걸음 한 걸음 만 하면 문제 가 없습니다.
시 작 된 준비 환경 설 치 는:
(1): nodeJS, 공식 사이트 에 다운로드 href
(2): 그리고 nodeJS 를 전역 환경 변수 에 추가 합 니 다 (nodeJS 가 설치 되면 npm 명령 을 사용 할 수 있 습 니 다). 참고 href.
(3): npm install grunt - g 와 npm install -g grunt - cli, 하 나 는 서버 를 설치 한 gurnt 이 고 하 나 는 클 라 이언 트 의 grunt (어차피 설 치 했 으 면 좋 겠 다) 입 니 다. 참고 href
  
첫 번 째 단계: Gruntfile. js 라 는 js 파일 을 새로 만 듭 니 다.
module.exports = function (grunt) {
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        connect: {
            options: {
                port: 9000,
                hostname: '127.0.0.1', //       ,         IP,localhost    
                livereload: 35729  //    watch      
            },
            server: {
                options: {
                    open: true, //       http://
                    base: [
              // severHttp ;
"html" // ] } } }, watch : { options: { livereload: 35729 // this port must be same with the connect livereload port }, scripts: { options: { livereload: true },
          // reload files : [
'**/*'] } } }); grunt.registerTask('default',["connect","watch"]); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-connect'); };

  
2: package. json 파일 을 새로 만 들 고 cmd (명령 행) 에서 npm install 을 실행 하면 모든 nodemodule 자동 다운로드 하기;
{
    "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 를 실행 합 니 다. grunt 는 모든 파일 의 변 화 를 자동 으로 감시 합 니 다. 파일 이 바 뀌 면, 127.0.0.1 을 통 해 열 린 모든 html 형식 파일 은 자동 으로 갱 신 됩 니 다.
;

좋은 웹페이지 즐겨찾기