【gulp-sass】error: File to import not found or unreadable

  簡要記錄一下在使用gulp-sass時候踩的坑,雖然不明因此然,可是彷佛在https://github.com/dlmanning/gulp-sass/issues/1 找到了答案。
在使用gulpfile配置監聽文件更新自動編譯時候出現了一個這個錯誤:「error: File to import not found or unreadable: ./m-bodycss


並且會出現一種奇怪的現象,當改動某個文件遇到這個報錯後再從新啓動編譯就正常監聽了該文件了,可是其餘文件卻不行,都是得在那個文件報錯後再從新啓動編譯才正常。
嘗試各類解決方案都無果,一度覺得是gulpfile文件編寫有錯:html

 1 var gulp = require('gulp');
 2 var sass = require('gulp-sass');
 3 var minifyCSS = require('gulp-minify-css');
 4 var rename = require('gulp-rename');
 5 var browserSync = require('browser-sync').create();
 6 
 7 // Static server
 8 gulp.task('browser-sync', function() {
 9     browserSync.init({
10         server: {
11             baseDir: './'
12         }
13     });
14 });
15 
16 // Build and Reload css files
17 gulp.task('compressCSS', function() {
18     gulp.src('src/styles/**/*.scss')
19         .pipe(sass({
20             outputStyle: 'compressed'
21         }))
22         .on('error', sass.logError)
23         .pipe(minifyCSS())
24         .pipe(rename({
25             suffix: '.min'
26         }))
27         .pipe(gulp.dest('prd/styles'))
28         .pipe(browserSync.stream());
29 });
30 
31 
32 // Reload HTML file
33 gulp.task('reloadHTML', function() {
34     gulp.src('./index.html')
35         .pipe(browserSync.stream());
36 });
37 
38 // Watch files for changes & recompile
39 gulp.task('watch', function() {
40     gulp.watch(['src/styles/**/*.scss'], ['compressCSS']);
41     gulp.watch(['./index.html'], ['reloadHTML']);
42 });
43 
44 // Default task, running just `gulp` will move font, compress js and scss, start server, watch files.
45 gulp.task('default', ['compressCSS', 'browser-sync', 'watch']);

最後在https://github.com/dlmanning/gulp-sass/issues/1 找到了答案:Sublime文本和緩慢的硬盤驅動器的組合形成的。 咱們可以經過將設置atomic_save更改成true來解決它。git

相關文章
相關標籤/搜索