nodejs-tw / ama

Ask me anything!
MIT License
31 stars 1 forks source link

gulp套件建立web,己可開起,無法對兩個html檔案進行連結 #10

Closed cn27529 closed 8 years ago

cn27529 commented 8 years ago

目的

我是新手,想採用gulp做為前端web應用

使用的工具

mac 10.10.5, node 2.14.12, gulp": "^3.9.1", gulp-connect": "^4.1.0", gulp-livereload": "^3.8.1", gulp-webserver": "^0.9.1"

操作流程

執行runweb任務後,己開啟預設的網頁

遇到的問題

1. 在app資料夾,己建立兩個檔案 about.html, prolife.html

  1. about.html 要連接到 prolife.html時,沒有反應

    嘗試過的解法

    程式碼

下面附上我的程式碼 https://github.com/cn27529/hello-gulp

cn27529 commented 8 years ago

first commit

yiskang commented 8 years ago
/// ============ for gulp-connect ============
var gulp = require('gulp'),
  connect = require('gulp-connect');

gulp.task('connect', function() {
  connect.server({
    root: 'app',
    port: 3000,
    livereload: true
  });
});

gulp.task('html', function () {
  gulp.src('./app/index.html')
    .pipe(connect.reload());
});

gulp.task('watch', function () {
  gulp.watch(['./app/*.html'], ['html']);
});

gulp.task('default', ['connect', 'watch']);
/// ============ for gulp-webserver ============
var gulp = require('gulp');
var webserver = require('gulp-webserver');

gulp.task('webserver',['watch'], function() {

  console.log('webserver task');
  gulp.src('./app')
    .pipe(webserver({
      livereload: true,
      directoryListing: {
        enable: false,
        path: './app',
        options: undefined
      },
      open: true,
      port: 8000
    }))

});

gulp.task('watch', function () {

  console.log('watch task');

  // livereload.listen();
  // gulp.watch('./app/*.html', ['html']);

  gulp.watch(['./app/*.html'], function(file){
    console.log('監控的檔案已變更:'+file.path);
  });
});

gulp.task( 'default', [ 'webserver' ] );
cn27529 commented 8 years ago

感謝指導,我置換試試

cn27529 commented 8 years ago

感謝,己OK,真不是很熟XD