前端工做流javascript
vue-cli ??? 自动打包
vue build打包时候其实就是在文件的合并,压缩,优化,到dist文件夹css
yarn add gulp -S
const gulp = require('gulp') // 任务名、任务事 gulp.task('hello', function () { console.log('Gulp负责前端开发阶段的任务,文件的合并,压缩,优化') })
gulp hello
gulp.task('default', ['hello'])
// src 表明根目录 gulp.task('copy-index', function() { return gulp.src('index.html') .pipe(gulp.dest('dist')) })
// *.*就是所有文件 // */* 走一级,匹配下一层 // **/* 全部都要 gulp.task('images', function () { return gulp.src('images/icons/*.{png,jpg}') .pipe(gulp.dest('dist/images/icon')) })
gulp.task('data', function () { return gulp.src(['xml/*.xml','json/*.json']) .pipe(gulp.dest('dist/data')) })
排除相似secret-01.json的文件html
return gulp.src(['xml/*.xml','json/*.json','!json/secret-*.json']) .pipe(gulp.dest('dist/data'))
gulp.task('copy-index', function() { return gulp.src('index.html') .pipe(gulp.dest('dist')) }) gulp.task('watch', function () { gulp.watch('index.html', ['copy-index']) })
开放监听前端
gulp watch
安装包vue
yarn add gulp-sass -S npm i gulp-sass --save-dev yarn add --dev gulp-sass
pipe过一下java
gulp.task('sass', function() { gulp.src('stylesheet/**/*.scss') .pipe(sass()) .pipe(gulp.dest('dist/css')) })
yarn add --dev gulp-connect
而后jquery
const connect = require('gulp-connect') gulp.task('server',function() { connect.server({ root: 'dist/', port: 3000, livereload: true }) }) gulp.task('watch', function() { gulp.watch('index.html', ['copy-index']) }) gulp.task('copy-index', function() { return gulp.src('index.html') .pipe(gulp.dest('dist')) .pipe(connect.reload()) }) gulp.task('default', ['server', 'watch'])
yarn add --dev gulp-concat
<script></script>
<script></script>vue-cli
这样引入??有两个请求哦!!减小请求数量!npm
gulp.task('script', function() { return gulp.src(['javascripts/jquery.js', 'javascripts/modernizr.js']) .pipe(concat('vendor.js')) .pipe(gulp.dest('dist/js')) })
const uglify = require('gulp-uglify') const rename = require('gulp-rename')
gulp.task('zip', function() { return gulp.src(['javascripts/jquery.js', 'javascripts/modernizr.js']) .pipe(concat('vendor.js')) .pipe(gulp.dest('dist/js')) .pipe(uglify()) .pipe(rename('vendor.min.js')) .pipe(gulp.dest('dist/js')) }) ##压缩css const minify = require('gulp-minify-css')
gulp.task('minify', function() {
gulp.src('stylesheet/*/.scss')json
.pipe(sass()) .pipe(gulp.dest('dist/css')) .pipe(minify()) .pipe(rename('style.min.css')) .pipe(gulp.dest('dist/css'))
})
##图片优化 const imagemin = require('gulp-imagemin')
gulp.task('imagemin', function() {
return gulp.src('images/icons/*.{png,jpg}')
.pipe(gulp.dest('dist/images/icon')) .pipe(imagemin()) .pipe(gulp.dest('dist/images/icon'))
})