web_Developer_Victor
@web_Developer_Victor
Что такое google?

Что от меня хочет Node.js?

Когда я запускаю gulpfile (а именно gulp html), по Node.js говорит, что я не выполнил какие-то обещания
[20:12:49] Starting 'html'...
(node:4548) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): [object Object]
(node:4548) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Gulpfile
/***************************************************\
|              Required all plugins                 |
\***************************************************/
const
	del          = require("del"),
	gulp         = require("gulp"),
	webp         = require("gulp-webp"),
	minify       = require("gulp-csso"),
	sass         = require("gulp-sass"),
	rename       = require("gulp-rename"),
	run          = require("run-sequence"),
	plumber      = require("gulp-plumber"),
	postcss      = require("gulp-postcss"),
	csscomb      = require("gulp-csscomb"),
	autoprefixer = require("autoprefixer"),
	posthtml     = require("gulp-posthtml"),
	svgstore     = require("gulp-svgstore"),
	imagemin     = require("gulp-imagemin"),
	imgRetina    = require("gulp-img-retina"),
	include      = require("posthtml-include"),
	resizer      = require("gulp-images-resizer"),
	server       = require("browser-sync").create();

/***************************************************\
|                Plugins settings                   |
\***************************************************/
const retinaOpts = {
	suffix: { 2: '@2x', 3: '@3x' }
};

/***************************************************\
|                    Gulp style                     |
\***************************************************/
gulp.task("style", function() {
	gulp.src("src/sass/style.scss")
		.pipe(plumber())
		.pipe(sass().on("error", sass.logError))
		.pipe(postcss([autoprefixer()]))
		.pipe(csscomb())
		.pipe(gulp.dest("build/css"))
		.pipe(minify())
		.pipe(rename("style.min.css"))
		.pipe(gulp.dest("build/css"))
		.pipe(server.stream());
});

/***************************************************\
|                    Gulp html                      |
\***************************************************/
gulp.task("html", function() {
	return gulp.src("src/*.html")
		.pipe(posthtml([
			include()
		]))
		.pipe(imgRetina(retinaOpts))
		.pipe(gulp.dest("build"));
});

/***************************************************\
|                    Gulp sprite                     |
\***************************************************/
gulp.task("sprite", function() {
	return gulp.src("src/img/svg/icon-*.svg")
		.pipe(svgstore({
			inlineSvg: true
		}))
		.pipe(rename("sprite.svg"))
		.pipe(gulp.dest("build/img"));
});

/***************************************************\
|               Gulp retina @2x                     |
\***************************************************/
gulp.task("retina@2x", function() {
	return gulp.src("src/img/**/*.{png,jpg,jpeg}")
		.pipe(gulp.dest("build/img"))
		.pipe(resizer({
			width: "200%"
		}))
		.pipe(rename({ suffix: "@2x"}))
		.pipe(gulp.dest("build/img"))
});

/***************************************************\
|               Gulp retina @3x                     |
\***************************************************/
gulp.task("retina@3x", function() {
	return gulp.src("src/img/**/*.{png,jpg,jpeg}")
		.pipe(gulp.dest("build/img"))
		.pipe(resizer({
			width: "300%"
		}))
		.pipe(rename({ suffix: "@3x"}))
		.pipe(gulp.dest("build/img"))
});

/***************************************************\
|               Gulp retina FULL                    |
\***************************************************/
gulp.task("retina", function(done) {
	run (
		"retina@2x",
		"retina@3x",
		done
	)
});

/***************************************************\
|               Gulp convert .webp                  |
\***************************************************/
gulp.task("webp", function() {
	return gulp.src("build/img/**/*.{png,jpg}")
		.pipe(webp({ quality: 90 }))
		.pipe(gulp.dest("build/img"))
});

/***************************************************\
|              Gulp minify img                      |
\***************************************************/
gulp.task("images", function() {
	return gulp.src("src/img/**/*.{png,jpg,svg}")
		.pipe(imagemin([imagemin.optipng({ optimizationLevel: 3 }),
			imagemin.jpegtran({ progressive: true }),
			imagemin.svgo()
		]))
		.pipe(gulp.dest("src/img"))
});

/***************************************************\
|           Gulp imageFullCycle                     |
\***************************************************/
gulp.task("imageFullCycle", function(done) {
	run (
		"sprite",
		"retina",
		"webp",
		"images",
		done
	)
});

/***************************************************\
|           Gulp copy all to build                  |
\***************************************************/
gulp.task("copy", function() {
	return gulp.src([
			"src/fonts/**/*.{woff,woff2}",
			"src/img/**",
			"src/js/**"
		], {
			base: "src"
		})
		.pipe(gulp.dest("build"));
});

/***************************************************\
|                 Gulp clean build                  |
\***************************************************/
gulp.task("clean", function() {
	return del("build");
});

/***************************************************\
|                    Gulp BUILD                     |
\***************************************************/
gulp.task("build", function(done) {
	run(
		"clean",
		"copy",
		"style",
		"imageFullCycle",
		"html",
		done
	);
});

/***************************************************\
|                    Gulp SERVER                     |
\***************************************************/
gulp.task("serve", function() {
	server.init({
		server: "build/"
	});

	gulp.watch("src/sass/**/*.scss", ["style"]);
	gulp.watch("src/*.html", ["html"]);
	gulp.watch("src/js/*.js").on("change", server.reload);
});


(мне кажется, что это что-то с include)
package.json
"scripts": {
    "test": "gulp style",
    "build": "gulp build",
    "start": "npm run build && gulp serve"
  },

  • Вопрос задан
  • 997 просмотров
Решения вопроса 1
web_Developer_Victor
@web_Developer_Victor Автор вопроса
Что такое google?
Проблема была не в gulp или node.js, а в путях при include (нужно указывать от файла gulpfile.js, а не от текущего файла)
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
ixon
@ixon

Это всего лишь предупреждение.
Отказ. Предупреждение. Отклонения от необработанных обещаний устарели. В будущем обещание отклонения, которое не обрабатывается, приведет к завершению процесса Node.js с ненулевым кодом выхода.
Ответ написан
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы