D
D
Dubrovin2018-08-04 20:43:36
gulp.js
Dubrovin, 2018-08-04 20:43:36

How to fix gulp config?

You need to make a replacement in the final CSS according to the template that is in the settings-default.json file, I write this config:

gulp.task( 'admin.css', () => {
  return gulp.src( [ 'framework/assets/scss/admin.scss', 'framework/blocks/*.scss' ] )
    .pipe( plumber() )
    .pipe( sassglob() )
    .pipe( sass() )
    .pipe( concat( 'admin.min.css' ) )
    .pipe( cssnano() )
    .pipe( replace( '/здесь регулярка/', () => {
      fs.readFile( 'settings-default.json', 'utf8', ( err, data ) => {
        if ( err ) {
          throw err;
        }
        //здесь берём данные из файла и делаем замену
        console.log( data ); //почему консоль лог срабатывает 4 раза?
      } );
      return //возвращаем результат для каждой замены;
    } ) )
    .pipe( gulp.dest( 'framework/assets/css' ) );
} );

In general, I am confused by the fact that the console log is triggered 4 times, i.e. reading from the file happens 4 times, but it needs to happen exactly 1 time after concatenation of all css into one admin.min.css. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dubrovin, 2018-08-04
@Dubrovin

Stepped myself, lights out, 4 times, because a match was found 4 times.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question