Answer the question
In order to leave comments, you need to log in
When I try to build a project, js is not compressed due to an error: TypeError: pipeline is not a function, what is the reason?
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cleanCSS = require('gulp-clean-css'),
rigger = require('gulp-rigger'),
uglify = require('gulp-uglify'),
pipeline = require('readable-stream').pipeline,
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
imageminZopfli = require('imagemin-zopfli'),
imageminPngquant = require('imagemin-pngquant'),
imageminMozjpeg = require('imagemin-mozjpeg'),
imageminGiflossy = require('imagemin-giflossy');
// сервер и отслеживающие файлы
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: {
baseDir: "./app"
}
});
gulp.watch("app/sass/*.scss", ['sass']);
gulp.watch("app/js/*.js").on('change', browserSync.reload);
gulp.watch("app/*.html").on('change', browserSync.reload);
});
// автокомпиляция сасс
gulp.task('sass', function() {
return gulp.src("app/sass/*.scss")
.pipe(sass())
.pipe(gulp.dest("app/css"))
.pipe(browserSync.stream());
});
// автопрефиксер
gulp.task('default', function () {
return gulp.src('app/css/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('css'));
});
// Ужимаем css
gulp.task('minify-css', function () {
return gulp.src('app/css/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('prodact/assets/style/'));
});
// Ужимаем JS
gulp.task('compress', function () {
return pipeline(
gulp.src('app/js/*.js'),
uglify(),
gulp.dest('prodact/assets/js/'));
});
// ужимаем изображения
gulp.task('gulp-imagemin', function () {
return gulp.src('app/images/**/*.{gif,png,jpg}')
.pipe(cache(imagemin([
//png
imageminPngquant({
speed: 1,
quality: [0.95, 1] // настройки с потерями
}),
imageminZopfli({
more: true,
iterations: 50 // очень медленно, но более эффективно
}),
imageminGiflossy({
optimizationLevel: 3,
optimize: 3, // keep-empty: сохранить пустые прозрачные рамки
lossy: 2
}),
//svg
imagemin.svgo({
plugins: [{
removeDimensions: true,
removeAttrs: true,
removeElementsByAttr: true,
removeStyleElement: true,
removeViewBox: false
}]
}),
//jpg не имеющий потерь
imagemin.jpegtran({
progressive: false
}),
//jpg очень легкие потери, используйте против jpegtran
imageminMozjpeg({
quality: 70
})
])))
.pipe(gulp.dest('prodact/assets/images/'));
});
gulp.task('default', ['serve','gulp-imagemin','minify-css', 'compress']);
Answer the question
In order to leave comments, you need to log in
pipeline = require('readable-stream').pipeline,
Nothing embarrassing after the requier?
The problem was solved by fixes:
pipeline = require('readable-stream').pipeline removed (.pipeline)
var pipeline = require('readable-stream');
and minor changes in the compression
task gulp.task('compress', function() {
return gulp.src('app/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('prodact /assets/js/'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question