Как переделать синтаксис gulpfile.js гальп 3 под гальп 4?
синтксис гальпа 3.9 перешел на 4 не знаю как исправить чего не хватает?
assert.js:341
throw err;
^
AssertionError [ERR_ASSERTION]: Task never defined: build
at getFunction (C:\rarus-test-master\node_modules\undertaker\lib\helpers\normalizeArgs.js:21:9)
at map (C:\rarus-test-master\node_modules\arr-map\index.js:20:14)
at normalizeArgs (C:\rarus-test-master\node_modules\undertaker\lib\helpers\normalizeArgs.js:30:10)
at Gulp.series (C:\rarus-test-master\node_modules\undertaker\lib\series.js:13:14)
at Object.<anonymous> (C:\rarus-test-master\gulpfile.js:119:26)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
PS C:\rarus-test-master>
const gulp = require('gulp');
const html = require('gulp-html');
const webpackStream = require('webpack-stream');
const gulpAutoprefix = require('gulp-autoprefixer');
const gulpSass = require('gulp-sass');
const gulpWatch = require('gulp-watch');
const gulpSourceMap = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
const gulpStylelint = require('gulp-stylelint');
const image = require('gulp-image');
const historyFallback = require('connect-history-api-fallback');
const webpackConfig = require('./webpack.config.js');
gulp.task('stylesheets', () => gulp.src('./src/scss/**/*.scss')
.pipe(gulpStylelint({
failAfterError: false,
reporters: [
{
formatter: 'string',
console: true,
fix: true,
},
],
}))
.pipe(gulpSourceMap.init())
.pipe(gulpSass({
outputStyle: 'compressed',
})).on('error', gulpSass.logError)
.pipe(gulpAutoprefix({
browsers: ['last 2 versions'],
}))
.pipe(gulpSourceMap.write())
.pipe(gulp.dest('./dev/css/'))
.pipe(browserSync.stream()));
gulp.task('stylesheetsProduction', () => gulp.src('./src/scss/**/*.scss')
.pipe(gulpStylelint({
failAfterError: true,
reporters: [
{
formatter: 'string',
console: true,
fix: true,
},
],
}))
.pipe(gulpSass({
outputStyle: 'compressed',
})).on('error', gulpSass.logError)
.pipe(gulpAutoprefix({
browsers: ['last 2 versions'],
}))
.pipe(gulp.dest('./build/css/')));
gulp.task('js', () => gulp.src('./src/js/main.js')
.pipe(webpackStream(webpackConfig))
.pipe(gulp.dest('./dev/js'))
.pipe(browserSync.stream()));
gulp.task('jsProduction', () => {
webpackConfig.watch = false;
gulp.src('./src/js/main.js')
.pipe(webpackStream(webpackConfig))
.pipe(gulp.dest('./build/js'));
});
gulp.task('image', () => gulp.src('./src/images/*')
.pipe(image())
.pipe(gulp.dest('./dev/images'))
.pipe(browserSync.stream()));
gulp.task('imageProduction', () => gulp.src('./src/images/*')
.pipe(image())
.pipe(gulp.dest('./build/images')));
gulp.task('html', () => gulp.src('./src/template/**/*.html')
.pipe(html())
.pipe(gulp.dest('./dev'))
.pipe(browserSync.stream()));
gulp.task('htmlProduction', () => gulp.src('./src/template/**/*.html')
.pipe(html())
.pipe(gulp.dest('./build')));
gulp.task('watch', () => {
gulpWatch(['./src/scss/**/*.scss'], () => {
gulp.start('stylesheets');
});
gulpWatch(['./src/images/**/*'], () => {
gulp.start('image');
});
gulpWatch(['./src/template/**/*.html'], () => {
gulp.start('html');
});
});
gulp.task('server', gulp.series(function () {
browser.init({
server: {
baseDir: './dev',
middleware: [
historyFallback(),
],
},
open: true,
port: 8080,
});
}));
gulp.task('server', gulp.series('build', function () {
browser.init({
server: {
baseDir: './dev',
middleware: [
historyFallback(),
],
},
open: true,
port: 8080,
});
}));
gulp.task('development', [
'stylesheets',
'js',
'image',
'html',
'watch',
'server',
]);
gulp.task('production', [
'stylesheetsProduction',
'jsProduction',
'imageProduction',
'htmlProduction',
]);
Ответы (1 шт):
Автор решения: Alexander Yukal
→ Ссылка
Посмотрите ответы здесь и здесь, в этих постах я постарался дать подробный ответ по использованию интерфейса Gulp 4 и из-за чего могут возникнуть проблемы. В самом низу вы найдете пример 4-ой версии.