N
N
Nikolai2019-05-21 19:13:59
gulp.js
Nikolai, 2019-05-21 19:13:59

Error building gulp project?

It starts, but as soon as you install any package or close the terminal, it stops working until you delete the node_modules folder and reinstall everything.
$ 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": []
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2019-06-06
@uselessmindYEAH

You need to install gulp globally
npm install --global gulp-cli

D
Denis Gaydak, 2017-05-22
@i0033

https://github.com/playgameservices/play-games-plu...
I'll just leave this here.
besides the fact that the version is more than a year old, would you like to clarify how you tested it? in the Editor (so he will not be able to log in to the editor, only on a live device and in the documentation they write about it)? On device? Show the log from the device with a request and a response, how much can I remember the "talkative" plugin?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question