Answer the question
In order to leave comments, you need to log in
Cannot set properties of undefined (setting 'style') what to do if this error occurs when working with gulp?
such an error vibrates when working with gulp yesterday everything was fine
here is the code
/**
* Подключение плагинов
*/
const gulp = require('gulp');
const argv = require('yargs').argv;
const browserSync = require('browser-sync').create();
const nunjucks = require('gulp-nunjucks');
const sass = require('gulp-sass')(require('sass'));
const sourcemaps = require('gulp-sourcemaps');
const gulpif = require('gulp-if');
const autoprefixer = require('gulp-autoprefixer');
const csso = require('gulp-csso');
const rename = require("gulp-rename");
const gcmq = require('gulp-group-css-media-queries');
/**
* Подключение файла настроек
*/
const projectConfig = require('./projectConfig.json');
/**
* Значения путей проекта
*/
const path = projectConfig.path;
/**
* Проверка на dev режим
*/
const isDev = function(){
return !argv.prod;
}
/**
* Проверка на prod режим
*/
const isProd = function(){
return !!argv.prod;
}
/**
* Serve
*/
function browsersync() {
browserSync.init({
open: true,
server: path.dist.distPath
});
}
function watch(){
gulp.watch(path.watch.html);
gulp.watch(path.watch.style, scss);
}
function scss(){
return gulp.src(path.src.style)
.pipe(gulpif(isDev(), sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(isProd(), autoprefixer({
grid: true
})))
.pipe(gulpif(isProd(), gcmq()))
.pipe(gulpif(isDev(), sourcemaps.write()))
.pipe(gulpif(isProd(), gulp.dest(path.dist.style)))
.pipe(gulpif(isProd(), csso()))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(path.dist.style))
.pipe(browserSync.reload({stream: true}))
}
path.src.style[0] = path.src.srcPath + path.src.style[0];
path.dist.style = path.dist.distPath + path.dist.style;
path.watch.style = [];
path.watch.style[0] = path.src.style[0].replace( path.src.style[0].split('/').pop(), '**/*.scss' );
exports.default = gulp.series(
gulp.parallel(browsersync, watch)
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question