Gulp sass 无法覆盖已经存在的文件 [英] Gulp sass unable to override already existing file

查看:77
本文介绍了Gulp sass 无法覆盖已经存在的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gulp sass/gulp watch 命令无法覆盖已经存在/生成的 .css 文件.因此,当文件夹中没有生成的 css 文件时,该命令可以正常工作.但是,如果该文件存在于文件夹中,则会出现以下错误.

Gulp sass/gulp watch command is unable to override the already existing/generated .css file. So when there is no generated css file in the folder, the command works fine. But, if the file exists on the folder I am getting below error.

[12:17:39] 错误:EPERM:不允许操作,打开'C:\My folder\project\components\site-products\demo\app\css\style.css'

[12:17:39] Error: EPERM: operation not permitted, open 'C:\My folder\project\components\site-products\demo\app\css\style.css'

 var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task('sass', function () {
  return gulp.src('./demo/app/scss/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./demo/app/css'));
});

gulp.task('sass:watch', function () {
  gulp.watch('./demo/app/scss/**/*.scss', ['sass']);
});

不确定是否相关,但我没有使用 gulp-compass.我正在使用 node-sass 代替.预先感谢您的帮助.

Not sure its relevant but I am not using gulp-compass. I am using node-sass instead. Thanks in advance for help.

推荐答案

我得到了同样的结果,并通过使用 gulp 缓存控制解决了.

I got the same and resolved by using gulp cache control.

我不明白为什么,但它有效!

I don't understand why, but it works!

对你来说,应该是这样的:

For you, it would be something like that:

var cache = require('gulp-cached');

gulp.task('cache:docsource', function(){
    return gulp.src('./demo/app/**/*.*').pipe(cache('cacheDocSource'));
});

gulp.task('sass', function () {
  return gulp.src('./demo/app/scss/**/*.scss')
    .pipe(cache('cacheDocSource'))
    .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
    .pipe(gulp.dest('./dist/demo/css'));
});

gulp.task('sass:watch', ['cache:docsource'], function () {
  gulp.watch('./demo/app/scss/**/*.scss', ['sass']);
});

这篇关于Gulp sass 无法覆盖已经存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆