@nikolay_akhmetyanov
Front-end developer

Ошибка при сборке проекта gulp?

Запускается, но стоит установить какой-либо пакет или завершить работу терминала перестает работать пока не удалишь папку node_modules и заново все не установишь.

$ gulp dev
[19:10:24] Local gulp not found in ~\Desktop\new-karapuz
[19:10:24] Try running: npm install gulp


var gulp = require('gulp'),
	del = require('del'),
	autoprefixer = require('gulp-autoprefixer'),
	browserSync = require('browser-sync'),
	sass = require('gulp-sass'),
	pug = require('gulp-pug'),
	concat = require("gulp-concat"),
	rename = require("gulp-rename"),
	imagemin = require('gulp-imagemin'),
	plumber = require('gulp-plumber');


var paths = {
	dirs: {
		build: './build'
	},
	html: {
		src: './src/pages/*.pug',
		dest: './build',
		watch: ['./src/pages/*.pug', './src/templates/*.pug', './src/blocks/**/*.pug']
	},
	css: {
		src: './src/styles/style.scss',
		dest: './build/css',
		watch: ['./src/blocks/**/*.scss', './src/styles/**/*.scss', './src/styles/*.scss']
	},
	js: {
		src: ['./node_modules/jquery/dist/jquery.min.js', './node_modules/popper.js/dist/umd/popper.min.js', './node_modules/bootstrap/dist/js/bootstrap.min.js', './node_modules/swiper/dist/js/swiper.min.js', './src/js/common.js', './src/blocks/**/*.js'],
		dest: './build/js',
		watch: ['./src/blocks/**/*.js', './src/js/common.js'],
		watchPlugins: './src/plugins/*.js'
	},
	images: {
		src: './src/blocks/**/img/*',
		dest: './build/img',
		watch: ['./src/blocks/**/img/*']
	},
	fonts: {
		src: './src/fonts/*',
		dest: './build/fonts',
		watch: './src/fonts/*'
	}
};

gulp.task('clean', function () {
	return del(paths.dirs.build);
});

gulp.task('templates', function () {
	return gulp.src(paths.html.src)
		.pipe(plumber())
		.pipe(pug({
			pretty: true
		}))
		.pipe(gulp.dest(paths.html.dest))
		.pipe(browserSync.reload({
			stream: true
		}));
});

gulp.task('styles', function () {
	return gulp.src(paths.css.src)
		.pipe(plumber())
		.pipe(sass())
		.pipe(autoprefixer({
			browsers: ['last 4 versions']
		}))
		.pipe(gulp.dest(paths.css.dest))
		.pipe(browserSync.reload({
			stream: true
		}));
});

gulp.task('scripts', function () {
	return gulp.src(paths.js.src)
		.pipe(plumber())
		.pipe(concat('scripts.js'))
		.pipe(gulp.dest(paths.js.dest));
});

gulp.task('images', function () {
	return gulp.src(paths.images.src)
		.pipe(plumber())
		.pipe(imagemin())
		.pipe(rename({
			dirname: ''
		}))
		.pipe(gulp.dest(paths.images.dest));
});

gulp.task('fonts', function () {
	return gulp.src(paths.fonts.src)
		.pipe(plumber())
		.pipe(gulp.dest(paths.fonts.dest))
		.pipe(browserSync.reload({
			stream: true
		}));
});

gulp.task('server', function () {
	browserSync.init({
		server: {
			baseDir: paths.dirs.build
		},
		reloadOnRestart: true
	});
	gulp.watch(paths.html.watch, gulp.parallel('templates'));
	gulp.watch(paths.css.watch, gulp.parallel('styles'));
	gulp.watch(paths.js.watch, gulp.parallel('scripts'));
	gulp.watch(paths.js.watchPlugins, gulp.parallel('scripts'));
	gulp.watch(paths.images.watch, gulp.parallel('images'));
	gulp.watch(paths.fonts.watch, gulp.parallel('fonts'));
});


gulp.task('build', gulp.series(
	'clean',
	'templates',
	'styles',
	'scripts',
	'images',
	'fonts'
));

gulp.task('dev', gulp.series(
	'build', 'server'
));


{
  "main": "gulpfile.js",
  "scripts": {
    "lint": "prettier --write \"src/blocks/**/*.scss\" \"src/styles/**/*.scss\" && stylelint \"src/blocks/**/*.scss\" \"src/styles/**/*.scss\" --fix --config ./.stylelintrc-format"
  },
  "dependencies": {
    "browser-sync": "^2.23.6",
    "gulp-autoprefixer": "^6.0.0",
    "gulp-concat": "^2.6.0",
    "gulp-pug": "^4.0.1",
    "gulp-sass": "^4.0.2",
    "npm": "^6.7.0",
    "optipng": "^2.0.0",
    "popper.js": "^1.15.0",
    "swiper": "^4.5.0"
  },
  "devDependencies": {
    "bootstrap": "^4.2.1",
    "del": "^3.0.0",
    "gulp": "github:gulpjs/gulp#4.0",
    "gulp-imagemin": "^5.0.3",
    "gulp-include": "^2.3.1",
    "gulp-plumber": "^1.2.0",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^3.0.1",
    "husky": "^1.1.3",
    "jquery": "^3.3.1",
    "lint-staged": "^8.0.4",
    "prettier": "^1.15.2",
    "rmdir": "^1.2.0",
    "stylelint": "^9.8.0",
    "stylelint-at-rule-no-children": "^0.3.1",
    "stylelint-config-prettier": "^4.0.0",
    "stylelint-config-recommended": "^2.1.0",
    "stylelint-declaration-block-no-ignored-properties": "^1.1.0",
    "stylelint-media-use-custom-media": "^1.0.0",
    "stylelint-order": "^1.0.0",
    "stylelint-value-no-unknown-custom-properties": "^2.0.0"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "linters": {
      "*.scss": [
        "prettier --write",
        "stylelint --fix --config ./.stylelintrc-format",
        "git add"
      ]
    },
    "ignore": []
  }
}
  • Вопрос задан
  • 306 просмотров
Пригласить эксперта
Ответы на вопрос 1
uselessmindYEAH
@uselessmindYEAH
Frontback cocaine developer
Нужно наверное глобально gulp установить
npm install --global gulp-cli
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы