-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gulpfile.js
167 lines (143 loc) · 4.61 KB
/
Gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* Created by Administrator on 2015/9/11.
*/
// 引入 gulp
var gulp = require('gulp');
var react = require('gulp-react');
// 引入组件
//var jshint = require('gulp-jshint');
var sass = require('gulp-sass'),
connect = require('gulp-connect'),
minifycss = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
browserify = require('gulp-browserify'),
browserSync = require('browser-sync').create(),
notify = require('gulp-notify'),
jshint = require('gulp-jshint'),
autoprefixer = require('gulp-autoprefixer'),
livereload = require('gulp-livereload'),
port = process.env.port || 5000;
// 检查脚本
//gulp.task('lint', function() {
// gulp.src('./js/*.js')
// .pipe(jshint())
// .pipe(jshint.reporter('default'));
//});
// Static server
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./"
}
});
});
// live reload
gulp.task('connect',function(){
connect.server({
// root:'./',
port: port,
livereload: true,
})
})
// reload Js
gulp.task('js',function(){
gulp.src('./dist/**/*.js')
.pipe( connect.reload() )
})
gulp.task('html',function(){
gulp.src('./*.html')
.pipe( connect.reload() )
});
//react 编译
gulp.task('react', function () {
return gulp.src('./src/login/js/main.js')
.pipe(browserify({
transform: 'reactify',
}))
.pipe(gulp.dest('./dist/login/js'));
});
// reload Js
gulp.task('js',function(){
gulp.src('./dist/**/js/*.js')
.pipe( connect.reload() )
.pipe(notify({ message: 'reload Js Ok' }));
})
//编译Sass,Autoprefix及缩小化
gulp.task('common', function() {
return gulp.src('./src/common/scss/panli.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/common/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/common/css'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Styles Common task complete' }));
/* gulp.src('./src/login/scss/!*.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/login/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/login/css'))
.pipe(notify({ message: 'Styles task complete' }));*/
});
//编译Sass,Autoprefix及缩小化
gulp.task('login', function() {
return gulp.src('./src/login/scss/login.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/login/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/login/css'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Styles Login task complete' }));
});
gulp.task('scripts', function() {
return gulp.src('./src/common/js/*.js')
.pipe(concat('panli.js'))
.pipe(gulp.dest('dist/common/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('dist/common/js'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Scripts task complete' }));
});
// 合并,压缩文件
/*gulp.task('js', function() {
gulp.src('./src/js/!*.js')
.pipe(concat('panli.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename('panli.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/js'));
});*/
// 默认任务
gulp.task('default', function(){
//gulp.run( 'sass', 'js','browser-sync');
gulp.run( 'styles', 'scripts');
var server = livereload();
/* // 监听文件变化
gulp.watch('./src/!**!/!*.*', function(file){
//gulp.run( 'sass', 'js','browser-sync');
gulp.run( 'styles', 'scripts');
});*/
});
/* 监听 */
gulp.task('watch', function() {
// 看守所有.scss档
gulp.watch('src/common/scss/*.scss', ['common']);
gulp.watch('src/login/scss/*.scss', ['login']);
// 看守所有.组件
gulp.watch('src/common/js/*.js', ['scripts']);
// 看守所有.js档
gulp.watch('src/**/js/*.js', ['js']);
// 看守所有. react
gulp.watch('./src/login/js/*.js', ['react']);
// 看守所有.html
gulp.watch('./*.html',['html']);
});
gulp.task('serve',['react','connect','watch']);