前端进阶之路-二、如何用gulp搭建一套web前端开发框架(2)
大家好,我是“廖某某前端日志”,今天为大家讲讲前端的进阶技能。
gulp-stylus //能将stylus语言打包成浏览器可运行的CSS代码
gulp-clean-css //压缩css文件
gulp-uglify //压缩JS代码
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install gulp-stylus gulp-uglify gulp-clean-css --save
const gulp = require('gulp');
const stylus = require('gulp-stylus');
const uglify = require('gulp-uglify');
const cleanCss = require('gulp-clean-css');
// HTML文件
const htmls = () => {
return gulp.src('src/view/**/*.html').pipe(gulp.dest('dist/view/'));
};
// CSS文件
const styles = () => {
return gulp
.src('src/css/**/*.styl')
.pipe(stylus())
.pipe(cleanCss())
.pipe(gulp.dest('dist/css/'));
};
// 图片文件
const images = () => {
return gulp
.src('src/images/**/*')
.pipe(gulp.dest('dist/images/'));
};
// JS文件
const scripts = () => {
return gulp
.src('src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js/'));
};
const prodbuild = gulp.series([htmls, styles, images, scripts]);
gulp.task('default',prodbuild);
div
width 100px
height 100px
格言:人生没有重来,每天都是现场直播!加油!