gulpfile
来源:互联网 发布:发那科机器人编程培训 编辑:程序博客网 时间:2024/06/08 19:49
// Generated on 2016-03-11 using generator-angular 0.15.1'use strict';var gulp = require('gulp');/* 读取package.json文件里的Dependencies相关配置项,调用gulp api,将gulp插件加载进来,返回对象是obj,该obj的key值与插件同名,指向每个插件,obj赋值给$符,方便后续直接通过$获取到插件的引用*/ var $ = require('gulp-load-plugins')();var openURL = require('open');var lazypipe = require('lazypipe');var rimraf = require('rimraf');var wiredep = require('wiredep').stream;var runSequence = require('run-sequence');/*声明app待编译路径和dist编译路径,dist路径上升一级,与app父级目录同级*/var yeoman = { app: require('./bower.json').appPath || 'app', dist: '../build'};/*paths管理*/var paths = { scripts: [yeoman.app + '/scripts/**/*.js'], styles: [yeoman.app + '/styles/**/*.scss'], test: ['test/spec/**/*.js'], testRequire: [ yeoman.app + '/bower_components/angular/angular.js', yeoman.app + '/bower_components/angular-mocks/angular-mocks.js', yeoman.app + '/bower_components/angular-resource/angular-resource.js', yeoman.app + '/bower_components/angular-cookies/angular-cookies.js', yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js', yeoman.app + '/bower_components/angular-route/angular-route.js', 'test/mock/**/*.js', 'test/spec/**/*.js' ], karma: 'karma.conf.js', views: { main: yeoman.app + '/main.html', login: yeoman.app + '/index.html', files: [yeoman.app + '/views/**/*.html'] }};////////////////////////// Reusable pipelines ///////////////////////////*scripts检测*/ var lintScripts = lazypipe() .pipe($.jshint, '.jshintrc') .pipe($.jshint.reporter, 'jshint-stylish');/*编译sacc,输出形式为expened的最接近手写css,precision 小数点保留位数autoprefixer 指定适配厂商前缀 ,输出流到'.tmp/styles'目录*/var styles = lazypipe() .pipe($.sass, { outputStyle: 'expanded', precision: 10 }) .pipe($.autoprefixer, 'last 1 version') .pipe(gulp.dest, '.tmp/styles');///////////// Tasks //////////////*sass编译*/gulp.task('styles', function () { return gulp.src(paths.styles) .pipe(styles());});/*scripts检测*/gulp.task('lint:scripts', function () { return gulp.src(paths.scripts) .pipe(lintScripts());});/*删除.tmp*/gulp.task('clean:tmp', function (cb) { rimraf('./.tmp', cb);});/*启动clinet,事先会启动server和编译sass*/gulp.task('start:client', ['start:server', 'styles'], function () { openURL('http://localhost:9000');});/*启动一个server,将app和.tmp置为根目录*/gulp.task('start:server', function() { $.connect.server({ root: [yeoman.app, '.tmp'], livereload: true, // Change this to '0.0.0.0' to access the server from outside. port: 9000 });});/*启动一个测试server*/gulp.task('start:server:test', function() { $.connect.server({ root: ['test', yeoman.app, '.tmp'], livereload: true, port: 9001 });});gulp.task('watch', function () { $.watch(paths.styles) .pipe($.plumber()) .pipe(styles()) .pipe($.connect.reload()); $.watch(paths.views.files) .pipe($.plumber()) .pipe($.connect.reload()); $.watch(paths.scripts) .pipe($.plumber()) .pipe(lintScripts()) .pipe($.connect.reload()); $.watch(paths.test) .pipe($.plumber()) .pipe(lintScripts()); gulp.watch('bower.json', ['bower']);});/*启动一个服务,先清除.tmp目录,再检测js代码,再启动客户端程序(启动一个服务器,并翻译sass),开始watch*/gulp.task('serve', function (cb) { runSequence('clean:tmp', ['lint:scripts'], ['start:client'], 'watch', cb);});/*启动一个服务,跑的程序是dist下的预发版程序*/gulp.task('serve:prod', function() { $.connect.server({ root: [yeoman.dist], livereload: true, port: 9000 });});gulp.task('test', ['start:server:test'], function () { var testToFiles = paths.testRequire.concat(paths.scripts, paths.test); return gulp.src(testToFiles) .pipe($.karma({ configFile: paths.karma, action: 'watch' }));});// 把真正所需要的文件引入到html文件中,就需要wiredep来帮忙//wiredep解决了bower前端库引入进html的问题// inject bower componentsgulp.task('bower', function () { return gulp.src(paths.views.main) .pipe(wiredep()) .pipe(gulp.dest(yeoman.app + '/'));});///////////// Build /////////////gulp.task('clean:dist', function (cb) { rimraf('../build', cb);});gulp.task('client:build', ['html', 'styles'], function () { /*js css在main.html中的引用会随文件名改变*/ var jsFilter = $.filter('**/*.js'); var cssFilter = $.filter('**/*.css'); return gulp.src(paths.views.main) .pipe($.useref({searchPath: [yeoman.app, '.tmp']})) .pipe(jsFilter) .pipe($.ngAnnotate()) .pipe($.uglify()) .pipe(jsFilter.restore()) .pipe(cssFilter) .pipe($.minifyCss({cache: true})) .pipe(cssFilter.restore()) .pipe($.rev()) .pipe($.revReplace()) .pipe(gulp.dest(yeoman.dist));});gulp.task('html', function () { return gulp.src(yeoman.app + '/views/**/*') .pipe(gulp.dest(yeoman.dist + '/views'));});gulp.task('images', function () { return gulp.src(yeoman.app + '/images/**/*') .pipe($.cache($.imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }))) .pipe(gulp.dest(yeoman.dist + '/images'));});gulp.task('copy:extras', function () { return gulp.src([yeoman.app + '/*.html','!'+yeoman.app +'/main.html']) .pipe(gulp.dest(yeoman.dist));});gulp.task('copy:fonts', function () { return gulp.src(yeoman.app + '/fonts/**/*') .pipe(gulp.dest(yeoman.dist + '/fonts'));});gulp.task('build', ['clean:dist'], function () { runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']);});gulp.task('default', ['build']);
0 0
- gulpfile
- gulpfile文件
- 我的gulpfile.js
- 简单gulpfile.js写法
- 基本gulpfile.js
- gulp配置文件gulpfile.js
- gulpfile.js的配置
- gulpfile.js文件内容
- Gulpfile.js 详解
- gulpfile.js常用配置文件
- gulpfile.js 备份
- 项目使用的gulpfile.js
- 前端 | 重构 gulpfile.js
- 利用gulpfile真机调试
- 个人项目习惯配置gulpfile
- 一份简单的gulpfile 配置文件
- No gulpfile found的解决办法
- 自动化构建工具Gulp配置文件gulpfile.js
- AsyncSocket
- mysql 出现column not found 问题
- 虚拟存储器
- 单链表的逆置(完整程序加思路分析)
- 基于Android Studio的内存泄漏检测与解决全攻略
- gulpfile
- MVC,MVP 和 MVVM 的图示
- android系统中与内存有关的文件及路径
- servlet1-生命周期
- Android Https
- Android Studio怎么查看程序的安全码获取SHA1值? 百度地图等开发
- 进程间通信 - 动态链接库中共享内存
- JS的encodeURI和java的URLDecoder.decode
- Word Break 单词分割