Sources: Gulp4.zip
Mistake:
assert.js:42 throw new errors.AssertionError({ ^ AssertionError [ERR_ASSERTION]: Task function must be specified at Gulp.set [as _setTask] (E:\Web\test\node_modules\undertaker\lib\set-task.js:10:3) at Gulp.task (E:\Web\test\node_modules\undertaker\lib\task.js:13:8) at Object.<anonymous> (E:\Web\test\gulpfile.js:224:6) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18)
Gulp version:
PS E:\Web\test> gulp -v [06:20:13] CLI version 2.0.1 [06:20:13] Local version 4.0.0
Npm version:
PS E:\Web\test> npm -v 6.5.0
package.json
{ "name": "html-ready", "version": "1.0.0", "description": "", "main": "gulpfile.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Devinora", "license": "ISC", "devDependencies": { "@babel/core": "^7.2.0", "@babel/preset-env": "^7.2.0", "babel-cli": "^6.26.0", "babel-core": "^6.26.3", "browser-sync": "^2.26.3", "gulp": "^4.0.0", "gulp-autoprefixer": "^6.0.0", "gulp-babel": "^8.0.0", "gulp-file-include": "^2.0.1", "gulp-imagemin": "^5.0.3", "gulp-minify-css": "^1.2.4", "gulp-plumber": "^1.2.1", "gulp-rename": "^1.4.0", "gulp-sass": "^4.0.2", "gulp-sourcemaps": "^2.6.4", "gulp-terser": "^1.1.6", "gulp-watch": "^5.0.1", "gulp.spritesmith": "^6.9.0", "imagemin-pngquant": "^6.0.0", "rimraf": "^2.6.2" }, "dependencies": { "npm": "^6.5.0" } }
gulpfile.js
'use strict'; var gulp = require('gulp'), watch = require('gulp-watch'), plumber = require('gulp-plumber'), prefixer = require('gulp-autoprefixer'), babel = require('gulp-babel'), terser = require('gulp-terser'), //альтернатива gulp-uglifyes sass = require('gulp-sass'), sourcemaps = require('gulp-sourcemaps'), fileinclude = require('gulp-file-include'), cssmin = require('gulp-minify-css'), imagemin = require('gulp-imagemin'), pngquant = require('imagemin-pngquant'), rimraf = require('rimraf'), browserSync = require("browser-sync"), rename = require('gulp-rename'), spritesmith = require('gulp.spritesmith'), reload = browserSync.stream; var path = { dist: { html: 'dist/', php: 'dist/', js: 'dist/js/', css: 'dist/css/', img: 'dist/img/', fonts: 'dist/fonts/' }, app: { html: 'app/*.html', php: 'app/*.php', js: 'app/js/main.js', jsInit: 'app/js/init.js', style: 'app/scss/main.scss', sprite: 'app/img/sprite/**/*.*', img: 'app/img/*.*', fonts: 'app/fonts/**/*.*', }, watch: { html: 'app/**/*.html', php: 'app/*.php', js: 'app/js/**/*.js', style: 'app/scss/**/*.scss', img: 'app/img/*.*', sprite: 'app/img/sprite/**/*.*', fonts: 'app/fonts/**/*.*' }, export: { img: 'app/img/', style: 'app/scss/imports/' }, spriteTemplate: 'sass.template.mustache', clean: './dist' }; var config = { server: { baseDir: "dist" // or ./dist }, // tunnel: true, // host: "178.150.110.97", // notify: false, logPrefix: "Frontend_Devil" }; gulp.task('webserver', function() { browserSync(config); }); gulp.task('clean', function(cb) { rimraf(path.clean, cb); }); gulp.task('html:dist', function() { gulp.src(path.app.html) .pipe(plumber()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(gulp.dest(path.dist.html)) .pipe(reload()); }); gulp.task('php:dist', function() { gulp.src(path.app.php) .pipe(plumber()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(gulp.dest(path.dist.php)) .pipe(reload()); }); gulp.task('js:dist', function() { //init.js //Файл для инициации // gulp.src(path.app.jsInit) // .pipe(plumber()) // .pipe(sourcemaps.init()) // .pipe(fileinclude({ // prefix: '@@', // basepath: '@file' // })) // .pipe(babel({ // presets: ["@babel/preset-env"] // })) // .pipe(terser()) // .pipe(sourcemaps.write()) // .pipe(rename({suffix: '.babel-min', prefix : ''})) // .pipe(gulp.dest(path.dist.js)) //Обычный js файл. gulp.src(path.app.js) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(sourcemaps.write()) .pipe(gulp.dest(path.dist.js)) //Babel-js файл. gulp.src(path.app.js) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(babel({ presets: ["@babel/preset-env"] })) .pipe(rename({ suffix: '.babel', prefix: '' })) .pipe(sourcemaps.write()) .pipe(gulp.dest(path.dist.js)) //Mini-js файл. gulp.src(path.app.js) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(terser()) //альтернатива uglifyes .pipe(sourcemaps.write()) .pipe(rename({ suffix: '.min', prefix: '' })) .pipe(gulp.dest(path.dist.js)); //Babel-mini-js файл. gulp.src(path.app.js) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(babel({ presets: ["@babel/preset-env"] })) .pipe(terser()) .pipe(sourcemaps.write()) .pipe(rename({ suffix: '.babel-min', prefix: '' })) .pipe(gulp.dest(path.dist.js)) .pipe(reload()); }); gulp.task('style:dist', function() { gulp.src(path.app.style) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe(sass({ sourceMap: true, errLogToConsole: true })) .pipe(prefixer()) .pipe(sourcemaps.write()) .pipe(gulp.dest(path.dist.css)) .pipe(cssmin()) .pipe(sourcemaps.write()) .pipe(rename({ suffix: '.min', prefix: '' })) .pipe(gulp.dest(path.dist.css)) .pipe(reload()); }); gulp.task('image:dist', function() { gulp.src(path.app.img) .pipe(plumber()) .pipe(imagemin({ progressive: true, svgoPlugins: [{ removeViewBox: false }], use: [pngquant()], interlaced: true })) .pipe(gulp.dest(path.dist.img)) .pipe(reload()); }); gulp.task('sprite:dist', function() { var spriteData = gulp.src(path.app.sprite) .pipe(plumber()) .pipe(spritesmith({ imgName: 'sprite.png', cssName: '_sprite.scss', cssFormat: 'scss', algorithm: 'binary-tree', cssTemplate: path.spriteTemplate, cssVarMap: function(sprite) { sprite.name = 's-' + sprite.name } })); spriteData.img.pipe(gulp.dest(path.export.img)); spriteData.css.pipe(gulp.dest(path.export.style)); }); gulp.task('fonts:dist', function() { gulp.src(path.app.fonts) .pipe(plumber()) .pipe(gulp.dest(path.dist.fonts)) }); gulp.task('dist', [ 'html:dist', 'php:dist', 'js:dist', 'sprite:dist', 'style:dist', 'fonts:dist', 'image:dist' ]); gulp.task('watch', function() { watch(path.watch.html, function(event, cb) { gulp.start('html:dist'); }); watch(path.watch.php, function(event, cb) { gulp.start('php:dist'); }); watch(path.watch.style, function(event, cb) { gulp.start('style:dist'); }); watch(path.watch.js, function(event, cb) { gulp.start('js:dist'); }); watch(path.watch.img, function(event, cb) { gulp.start('image:dist'); }); watch(path.watch.sprite, function(event, cb) { gulp.start('sprite:dist'); }); watch(path.watch.fonts, function(event, cb) { gulp.start('fonts:dist'); }); }); gulp.task('default', ['dist', 'webserver', 'watch']);
Partial solution
The problem was that when switching to the new Gulp 4 , they did not do backward compatibility. I do not know why, and whether this is justified, but below I will give an example that helped me.
They added two new methods: gulp.series
, gulp.parallel
.
It was:
gulp.task('dist', [ 'html:dist', 'php:dist', 'js:dist', 'sprite:dist', 'style:dist', 'fonts:dist', 'image:dist' ]); gulp.task('watch', function() { watch(path.watch.html, function(event, cb) { gulp.start('html:dist'); }); watch(path.watch.php, function(event, cb) { gulp.start('php:dist'); }); watch(path.watch.style, function(event, cb) { gulp.start('style:dist'); }); watch(path.watch.js, function(event, cb) { gulp.start('js:dist'); }); watch(path.watch.img, function(event, cb) { gulp.start('image:dist'); }); watch(path.watch.sprite, function(event, cb) { gulp.start('sprite:dist'); }); watch(path.watch.fonts, function(event, cb) { gulp.start('fonts:dist'); }); }); gulp.task('default', ['dist', 'webserver', 'watch']);
It became:
//Удалил // gulp.task('dist', [ // 'html:dist', // 'php:dist', // 'js:dist', // 'sprite:dist', // 'style:dist', // 'fonts:dist', // 'image:dist' // ]); gulp.task('watch', function() { gulp.watch(path.watch.html, function(event, cb) { gulp.start('html:dist'); }); gulp.watch(path.watch.php, function(event, cb) { gulp.start('php:dist'); }); gulp.watch(path.watch.style, function(event, cb) { gulp.start('style:dist'); }); gulp.watch(path.watch.js, function(event, cb) { gulp.start('js:dist'); }); gulp.watch(path.watch.img, function(event, cb) { gulp.start('image:dist'); }); gulp.watch(path.watch.sprite, function(event, cb) { gulp.start('sprite:dist'); }); gulp.watch(path.watch.fonts, function(event, cb) { gulp.start('fonts:dist'); }); }); gulp.task('default', gulp.parallel( 'html:dist', 'php:dist', 'js:dist', 'sprite:dist', 'style:dist', 'fonts:dist', 'image:dist', 'webserver', 'watch' ));
PS: At the expense of the spelling of gulp.task('watch')
I doubt it, but this decision helped me.
PSS: This is a small part of the problems. I would be grateful if you edit gulpfile.js
as needed. If you need source, let me know.
[07:12:09] Starting '<anonymous>'... [07:12:09] '<anonymous>' errored after 2.72 ms [07:12:09] TypeError: gulp.start is not a function at E:\Web\test\gulpfile.js:227:8 at bound (domain.js:301:14) at runBound (domain.js:314:12) at asyncRunner (E:\Web\test\node_modules\async-done\index.js:55:18) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickDomainCallback (internal/process/next_tick.js:218:9)