I
I
Ivan2020-04-29 18:16:29
gulp.js
Ivan, 2020-04-29 18:16:29

Connecting normalize.css with gulp?

I ask for help, please tell me in detail how I can include in the existing gulpfile nozmalize.css. I installed it via npm, but I can't figure out what changes to add to the gulpfile in order for everything to work. And if any other plugin I want to connect how to do it?

const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();

function style() {
  return gulp.src('./scss/**/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('./css'))
    .pipe(browserSync.stream())
}


function watch() {
  browserSync.init({
    server: {
      baseDir: './'
    }
  })
  gulp.watch('./scss/**/*scss', style);
  gulp.watch('./*.html').on('change', browserSync.reload);
}

exports.style = style;
exports.watch = watch;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
raury, 2020-04-29
@raury

You can write a new task to include styles from different libraries:
First you need to install the 'gulp-concat' package and include it

const concat = require('gulp-concat');

gulp.task('css-libs', function(){
    return gulp.src('node_modules/normalize.css/normalize.css')
        .pipe(concat('_libs.scss'))
        .pipe(gulp.dest('./scss'))
        .pipe(browserSync.reload({stream: true}))
})

Now, when you want to add some other css library, instead of a string, you pass an array to gulp.scr().
You can check my build https://github.com/azzztec/gulp-assemble/blob/mast...

M
Michael, 2020-04-29
@notiv-nt

const gulp = require('gulp');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const postcssImport = require('postcss-import');

module.exports.css = () => {
  return gulp
    .src('./scss/**/*.scss')
    .pipe(sass())
    .pipe(postcss([postcssImport()]))
    .pipe(gulp.dest('./css'));
};

@import 'normalize.css';
You will be using postcss anyway, so use postcss-import

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question