0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gulpでscssファイルをcssにコンパイルしてもcssの更新日が変わらない問題

Last updated at Posted at 2020-02-15

コンパイルしたcssをsftp使ってサーバー上にあげたいなと思いやってみたらものすごく苦戦してしまってその時のことをまとめます。

#問題点
なぜかscssをgulpでcssにコンパイルしても更新日が変わらずwatch出来ず苦戦してました。
きっと内容が更新されてるだけで保存されてないんでしょうね。しみじみ

##やったこと
とりあえずファイルが更新されれば一件落着なので下記のプラグインを入れるだけでした。

yarn
yarn global add through2

npm
npm install -g gthrough2
const gulp = require('gulp');
const sass = require('gulp-sass');
const through2 = require('through2');

gulp.task('scss', function () {
  return gulp.src(['scss/*.scss'])
    .pipe(plumber())
    .pipe(sass({ outputStyle: 'expanded' }))
    .on('error', sass.logError)
   // 更新日を書き換える
    .pipe(through2.obj((chunk, enc, callback) => {
      const date = new Date();
      chunk.stat.atime = date;
      chunk.stat.mtime = date;
      callback(null, chunk);
    }))
    .pipe(gulp.dest('css/'));
});

これで無事cssファイルが更新されwatchが出来てサーバーに上げることが出来ました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?