gulp举例
来源:互联网 发布:extend软件 编辑:程序博客网 时间:2024/04/29 22:25
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var paths = {
sass: ['app/scss/**/*.scss'],
src: 'app',
dist: 'www'
};
gulp.task('default', ['sass', 'concat-controllers', 'concat-services', 'concat-directives', 'concat-filters']);
gulp.task('sass', function (done) {
gulp.src('app/scss/*.scss')
.pipe(sass())
.on('error', sass.logError)
// .pipe(minifyCss({
// keepSpecialComments: 0
// }))
// .pipe(rename({ extname: '.min.css' }))
.pipe(concat('style.css'))
.pipe(gulp.dest('app/css/'))
.on('end', done);
});
gulp.task('install', ['git-check'], function () {
return bower.commands.install()
.on('log', function (data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function (done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
// Angular合并js
gulp.task('concat-controllers', function () {
gulp.src(['app/js/controllers/base.js', 'app/js/controllers/*.js'])
.pipe(concat('controllers.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-services', function () {
gulp.src(['app/js/services/base.js', 'app/js/services/*.js'])
.pipe(concat('services.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-directives', function () {
gulp.src(['app/js/directives/base.js', 'app/js/directives/*.js'])
.pipe(concat('directives.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-filters', function () {
gulp.src(['app/js/filters/base.js', 'app/js/filters/*.js'])
.pipe(concat('filters.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('watch', ['default'], function () {
gulp.watch(paths.sass, ['sass']);
// AngularJS文件监听
gulp.watch('app/js/controllers/*.js', ['concat-controllers'], function (event) {
console.log('Concat controllers ' + event.path);
});
gulp.watch('app/js/services/*.js', ['concat-services'], function (event) {
console.log('Concat services' + event.path);
});
gulp.watch('app/js/directives/*.js', ['concat-directives'], function (event) {
console.log('Concat directives' + event.path);
});
gulp.watch('app/js/filters/*.js', ['concat-filters'], function (event) {
console.log('Concat filters' + event.path);
});
});
// build
gulp.task('build', ['default'], function () {
// 拷贝css并压缩
gulp.src(paths.src + '/css/**/*.css')
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(gulp.dest(paths.dist + '/css'));
// 拷贝img
gulp.src(paths.src + '/img/**')
.pipe(gulp.dest(paths.dist + '/img'));
// 拷贝js
gulp.src(paths.src + '/js/*.js')
.pipe(gulp.dest(paths.dist + '/js'));
// 拷贝lib
gulp.src(paths.src + '/lib/**')
.pipe(gulp.dest(paths.dist + '/lib'));
// 拷贝templates
gulp.src(paths.src + '/templates/**')
.pipe(gulp.dest(paths.dist + '/templates'));
// 拷贝manifest.json
gulp.src(paths.src + '/manifest.json')
.pipe(gulp.dest(paths.dist));
// 拷贝service-worker.js
gulp.src(paths.src + '/service-worker.js')
.pipe(gulp.dest(paths.dist));
// 拷贝index.html
gulp.src(paths.src + '/index.html')
.pipe(gulp.dest(paths.dist));
});
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var paths = {
sass: ['app/scss/**/*.scss'],
src: 'app',
dist: 'www'
};
gulp.task('default', ['sass', 'concat-controllers', 'concat-services', 'concat-directives', 'concat-filters']);
gulp.task('sass', function (done) {
gulp.src('app/scss/*.scss')
.pipe(sass())
.on('error', sass.logError)
// .pipe(minifyCss({
// keepSpecialComments: 0
// }))
// .pipe(rename({ extname: '.min.css' }))
.pipe(concat('style.css'))
.pipe(gulp.dest('app/css/'))
.on('end', done);
});
gulp.task('install', ['git-check'], function () {
return bower.commands.install()
.on('log', function (data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function (done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
// Angular合并js
gulp.task('concat-controllers', function () {
gulp.src(['app/js/controllers/base.js', 'app/js/controllers/*.js'])
.pipe(concat('controllers.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-services', function () {
gulp.src(['app/js/services/base.js', 'app/js/services/*.js'])
.pipe(concat('services.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-directives', function () {
gulp.src(['app/js/directives/base.js', 'app/js/directives/*.js'])
.pipe(concat('directives.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('concat-filters', function () {
gulp.src(['app/js/filters/base.js', 'app/js/filters/*.js'])
.pipe(concat('filters.js'))
.pipe(gulp.dest('app/js'));
});
gulp.task('watch', ['default'], function () {
gulp.watch(paths.sass, ['sass']);
// AngularJS文件监听
gulp.watch('app/js/controllers/*.js', ['concat-controllers'], function (event) {
console.log('Concat controllers ' + event.path);
});
gulp.watch('app/js/services/*.js', ['concat-services'], function (event) {
console.log('Concat services' + event.path);
});
gulp.watch('app/js/directives/*.js', ['concat-directives'], function (event) {
console.log('Concat directives' + event.path);
});
gulp.watch('app/js/filters/*.js', ['concat-filters'], function (event) {
console.log('Concat filters' + event.path);
});
});
// build
gulp.task('build', ['default'], function () {
// 拷贝css并压缩
gulp.src(paths.src + '/css/**/*.css')
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(gulp.dest(paths.dist + '/css'));
// 拷贝img
gulp.src(paths.src + '/img/**')
.pipe(gulp.dest(paths.dist + '/img'));
// 拷贝js
gulp.src(paths.src + '/js/*.js')
.pipe(gulp.dest(paths.dist + '/js'));
// 拷贝lib
gulp.src(paths.src + '/lib/**')
.pipe(gulp.dest(paths.dist + '/lib'));
// 拷贝templates
gulp.src(paths.src + '/templates/**')
.pipe(gulp.dest(paths.dist + '/templates'));
// 拷贝manifest.json
gulp.src(paths.src + '/manifest.json')
.pipe(gulp.dest(paths.dist));
// 拷贝service-worker.js
gulp.src(paths.src + '/service-worker.js')
.pipe(gulp.dest(paths.dist));
// 拷贝index.html
gulp.src(paths.src + '/index.html')
.pipe(gulp.dest(paths.dist));
});
0 0
- gulp举例
- gulp
- Gulp
- gulp
- Gulp
- gulp
- gulp
- gulp
- gulp
- gulp
- gulp
- gulp
- Gulp
- gulp
- Gulp
- gulp
- gulp
- gulp
- ubuntu root 用户切换到普通用户
- [NLP论文阅读]Distributed Representations of Sentences and Documents
- 排序(二)----希尔排序
- View.onMeasure()
- Intelx86使用的寄存器
- gulp举例
- VBA_批量调整图片宽度
- 给linux添加一个系统调用(linux-4.10.1)
- iOS 定位功能的实现详解
- OC的内存管理
- leetcodeOJ 62. Unique Paths
- 答题卡识别软件
- BZOJ P1497[NOI2006]最大获利
- VS2013 无法使用'inet_ntoa'