const gulp = require('gulp');
const less = require('gulp-less');
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const connect = require('gulp-connect');
const px2rem = require('gulp-px2rem-plugin');
gulp.task('less', function(done) {
return gulp.src('src/css/**/*.less')
.pipe(less())
.pipe(autoprefixer({
overrideBrowserslist:['> 1%', 'Firefox >= 10', 'ie >= 9', 'iOS >= 4', 'Chrome >= 10'],
cascade: false
}))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/style'))
.pipe(connect.reload());
done()
});
gulp.task('cass', function(done) {
return gulp.src('src/css/**/*.css')
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/style'))
.pipe(connect.reload());
done()
});
gulp.task('html',function(done){
return gulp.src('./src/*.html')
.pipe(gulp.dest('dist/'))
.pipe(connect.reload()); // 刷新浏览器
done()
})
gulp.task('js',function(done){
return gulp.src('./src/js/**/*')
.pipe(gulp.dest('dist/js/'))
.pipe(connect.reload());
done()
});
gulp.task('images',function(done){
return gulp.src('./src/images/**/*')
.pipe(gulp.dest('dist/images/'))
.pipe(connect.reload());
done()
});
gulp.task('watch', function () {
gulp.watch('./src/js/**/*.js', gulp.series('js') );
gulp.watch('./src/css/**/*.less', gulp.series('less'));
gulp.watch('./src/css/**/*.css', gulp.series('cass'));
gulp.watch('./src/images/**/*', gulp.series('images'));
gulp.watch('./src/*.html', gulp.series('html') );
})
gulp.task('webserver', function() {
connect.server({
root: './dist/',
livereload: true,// 自动刷新
port: 2333,
host: '::'
});
});
gulp.task('default',gulp.parallel('less','js','html','webserver','watch','images','cass'));//并行执行
// gulp.task('default',gulp.series('styles','scripts'));//按顺序执行
package.js 文件
{
"name": "aaaa",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^9.7.4",
"gulp-autoprefixer": "^7.0.1",
"gulp-connect": "^5.7.0",
"gulp-less": "^4.0.1",
"gulp-px2rem-plugin": "^0.4.0",
"gulp-rename": "^2.0.0",
"gulp-ruby-sass": "^4.0.0"
},
"browserslist": [
"defaults",
"> 1%",
"last 2 versions",
"not ie <= 8",
"ios > 7"
],
"dependencies": {
"gulp": "^4.0.2"
}
}