Answer the question
In order to leave comments, you need to log in
Task gulp for min.js?
I can't build a task to minimize js, how to implement it correctly?
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const pug = require('gulp-pug');
const sass = require('gulp-sass');
const spritesmith = require('gulp.spritesmith');
const rimraf = require('rimraf');
const rename = require('gulp-rename');
const prefix = require('gulp-autoprefixer');
// const uglify = require('gulp-uglify');
// const sourcemaps = require('gulp-sourcemaps');
// BROWSER SYNC
gulp.task('server', function() {
browserSync.init({
server: {
port:9000,
baseDir: "build"
}
});
gulp.watch('build/**/*').on('change', browserSync.reload);
});
// PUG
gulp.task('templates:compile', function buildHTML() {
return gulp.src('source/template/index.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('build'))
});
//SASS
gulp.task('styles:compile', function () {
return gulp.src('source/styles/main.scss')
.pipe(prefix("last 2 version", "> 1%", "ie 8", "ie 7"))
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(rename('main.min.css'))
.pipe(gulp.dest('build/css'));
});
//SPRITESMITH
gulp.task('sprite', function (cd) {
const spriteData = gulp.src('source/images/icons/*.png').pipe(spritesmith({
imgName: 'sprite.png',
imgPath: '../images/sprite.png',
cssName: 'sprite.scss'
}));
spriteData.img.pipe(gulp.dest('build/images/'));
spriteData.css.pipe(gulp.dest('source/styles/global/'));
cd();
});
//CLEAN
gulp.task('clean', function del(cd){
return rimraf('build', cd);
});
//COPY FONTS
gulp.task('copy:fonts', function(){
return gulp.src('./source/fonts/**/*.*')
.pipe(gulp.dest('build/fonts'));
});
//COPY IMAGES
gulp.task('copy:images', function(){
return gulp.src('./source/images/**/*.*')
.pipe(gulp.dest('build/images'));
});
//COPY
gulp.task('copy', gulp.parallel('copy:fonts', 'copy:images'));
//WATCH
gulp.task('watch', function () {
gulp.watch('source/template/**/*.pug', gulp.series('templates:compile'));
gulp.watch('source/styles/**/*.scss', gulp.series('styles:compile'));
});
//DEFAULT
gulp.task('default', gulp.series(
'clean',
gulp.parallel('templates:compile', 'styles:compile', 'copy'),
gulp.parallel('watch', 'server')
)
);
Answer the question
In order to leave comments, you need to log in
I do like this:
gulp.task('scripts-libs', function(){
return gulp.src([
'app/libs/jquery/jquery.js',
'app/libs/**/*.js'
])
.pipe(concat('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest('app/js'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question