2017-04-03 90 views
1

gulp build command命令提示符在dist文件夾中創建一個文件夾js和一個文件scripts.js。但同樣不會爲Css和Html創建。我的css和Html文件夾有一個文件,不是空的。Gulp不會生成預期的Css和Html文件夾

const gulp = require('gulp'); 
const concat = require('gulp-concat'); 
const browserSync = require('browser-sync').create(); 

const scripts = require('./scripts'); 
const styles = require('./styles'); 

var devMode = false; 



gulp.task('css',function(){ 
    gulp.src(styles) 
     .pipe(concat('main.css')) 
     .pipe(gulp.dest('./dist/css')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

gulp.task('js',function(){ 
    gulp.src(scripts) 
     .pipe(concat('scripts.js')) 
     .pipe(gulp.dest('./dist/js')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

gulp.task('html',function(){ 
    gulp.src('./src/templates/**/*.html') 
     .pipe(gulp.dest('./dist/html')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

gulp.task('build',function(){ 
    gulp.start(['css','js','html']) 
}); 

gulp.task('browser-sync',function(){ 
    browserSync.init(null,{ 
     open : false, 
     server : { 
      baseDir : 'dist' 
     } 
    }) 
}); 

gulp.task('start',function(){ 
    devMode = true; 
    gulp.start(['build','browser-sync']); 
    gulp.watch(['./src/css/**/*.css'],['css']); 
    gulp.watch(['./src/js/**/*.js'],['js']); 
    gulp.watch(['./src/templates/**/*.html'],['html']); 
}); 

Following is the output

The project structure

+0

你能提供你的應用程序/目錄結構嗎? – 32teeths

+0

我已經提供了一個鏈接到項目結構 – FalconFlyer

回答

1

我會建議你使用自耕農與發電機一樣Fountain,讓你不花你的時間建設吞氣任務。噴泉有一個非常好的吞嚥設置,你可以根據你的需要進行定製。

使用gulp.src加載文件時,您需要將路徑傳遞給文件,在這裏您只提到了gulp.src(require(./styles)),我不確定該文件是否有效。相反,通過,gulp.src('**/*.css')這將掃描所有的文件夾,並採取所有的.css文件。

+0

我是新來的吞嚥,所以從基礎開始。 – FalconFlyer

+0

我在我的styles.js文件中有這條線[ 「./src/css/**/*.css」 ] – FalconFlyer

+0

這應該與您如何提及文件路徑有關。 '。/'會指向當前目錄,不需要在其中添加'src'。在你提到的項目結構中,'./css/* .css'將包含css文件夾中的所有文件,並且這些文件應該適用於你。 – 32teeths

相關問題