2017-07-28 21 views
0

首先,我知道關於這個主題有幾個關於SO的問題,但我試圖使用他們的任務結構和它們的修復,但沒有任何工作對我來說。觀看樣式並運行一個nodemon服務器,吞下一滴

我現在只是看我的樣式,我會在稍後添加腳本和圖像。

這裏是我的gulpfile.js

'use strict'; 
var gulp = require('gulp'); 
var sass = require('gulp-sass'); 
var autoprefixer = require('autoprefixer'); 
var cssnano = require('gulp-cssnano'); 
var postcss = require('gulp-postcss'); 
var watch = require('gulp-watch'); 
var sourcemaps = require('gulp-sourcemaps'); 
var lost = require('lost'); 
var nodemon = require('gulp-nodemon'); 
var config = require('./config.js'); 

// Getting app name 
var contract = config.contract; 

// Directories 
var dirs = { 
    stylesSrc: '_assets/' + contract + 'styles/scss/**/*.scss', 
    stylesDest: '_assets/' + contract + 'styles/css' 
}; 

// Styles task with autoprefixer and lostgrid 
gulp.task('styles',() => { 
    return gulp.src(dirs.stylesSrc) 
     .pipe(sass()) 
     .pipe(postcss([ 
      autoprefixer({ 
       browsers: [ 
        "Android 2.3", 
        "Android >= 4", 
        "Chrome >= 20", 
        "Firefox >= 24", 
        "Explorer >= 8", 
        "iOS >= 6", 
        "Opera >= 12", 
        "Safari >= 6" 
       ] 
      }), 
      lost() 
     ])) 
    .pipe(gulp.dest(dirs.stylesDest)) 
}); 

// Watch styles 
gulp.task('watch', function(){ 
    gulp.watch(dirs.stylesSrc, ['styles']); 
}) 

// Nodemon server 
gulp.task('serve', function(){ 
    nodemon({'script': 'server.js'}); 
}); 

// Start server and watch for development 
gulp.task('default', ['serve', 'watch']); 

我已經嘗試了幾次反覆,但是這是目前的一個,似乎工作,但不看。這裏是終端輸出:

npm run start 
gulp 
Using gulpfile ~/Development/projectTitle/gulpfile.js 
Starting 'serve'... 
Finished 'serve' after 36 ms 
Starting 'watch'... 
Finished 'watch' after 9.64 ms 
Starting 'default'... 
Finished 'default' after 23 μs 
[nodemon] 1.11.0 
[nodemon] to restart at any time, enter `rs` 
[nodemon] watching: *.* 
[nodemon] starting `node server.js` 
Server listening on port 8086 

當我保存的Sass與更改文件沒有任何反應。

歡迎任何建議,謝謝!

+0

你的config.contract是否有尾隨路徑分隔符(如「/」)?如果在拼接到'styles/scss/**/*。scss'之前是否應該有一個? – Mark

回答

0

這與Mark的註釋路徑一致。需要注意URL路徑中的前綴和後綴斜槓。