-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
187 lines (159 loc) · 4.38 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* @author yongbingzhang@Ctrip
* boxDialog 通用弹窗组件
*/
var gulp = require('gulp'),
os = require('os'),
concat = require('gulp-concat'),
gulpOpen = require('gulp-open'),
uglify = require('gulp-uglify'),
mincssmin = require('gulp-minify-css'),
clean = require('gulp-clean'),
gulpWebpack = require('gulp-webpack'),
webpackConfig = require('./webpack.config.js'),
rename = require('gulp-rename'),
connect = require('gulp-connect');
// 路径缓存
var _src = './src',
_bulid = './dist';
var srcPath = {
src: _src,
app: _src+'/app',
appinc: _src+'/appinc',
skins: _src+'/skins',
sass: _src+'/skins-sass/sass',
images: _src+'/images',
js: _src+'/js',
module: _src+'/js/component',
lib: _src+'/js/lib'
};
var bulidPath = {
bulid: _bulid,
app: _bulid+'/app',
skins: _bulid+'/skins',
css: _bulid+'/css',
images: _bulid+'/images',
js: _bulid+'/js'
};
var host = {
path: srcPath.src,
port: 1000,
html: 'index.html',
url: 'http://localhost:1000/app'
};
//mac chrome: "Google chrome",
var browser = os.platform() === 'linux' ? 'Google chrome' : (
os.platform() === 'darwin' ? 'Google chrome' : (
os.platform() === 'win32' ? 'chrome' : 'firefox'));
/********sass处理*********/
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src(srcPath.sass +'/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(srcPath.skins));
});
var compass = require('gulp-compass');
gulp.task('compass', function(done) {
gulp.src(srcPath.sass +'/**/*.scss')
.pipe(compass({
config_file: './config.rb',
css: srcPath.css,
sass: srcPath.sass
}))
.on('end', done)
.pipe(connect.reload());
//.pipe(gulp.dest(bulidPath.css));
});
//将图片拷贝到目标目录
gulp.task('copy:images', function () {
gulp.src([srcPath.images+'/**/*'])
.pipe(gulp.dest(bulidPath.images));
});
//压缩合并css
gulp.task('cssmin',['compass'],function () {
gulp.src(srcPath.css+'/*.css')
.pipe(mincssmin())
.pipe(gulp.dest(bulidPath.css));
});
//压缩js
gulp.task('jsmin',function () {
/*
gulp.src(srcPath.js+'/*.js')
.pipe(gulp.dest(bulidPath.js));
*/
gulp.src(srcPath.js+'/*.js')
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(bulidPath.js));
});
//压缩js
gulp.task('jsmin2',function () {
gulp.src(srcPath.js+'/demojs/*.js')
.pipe(uglify())
.pipe(gulp.dest(bulidPath.js));
});
//用于在html文件
gulp.task('html', function (done) {
gulp.src(srcPath.app)
.on('end', done)
.pipe(connect.reload());
});
//将html拷贝到目标目录
gulp.task('copy:html', function () {
gulp.src([srcPath.app+'/*.html'])
.pipe(gulp.dest(bulidPath.app));
});
gulp.task('copy:skins', function () {
gulp.src([srcPath.skins+'/*.css',srcPath.skins+'/icons/'])
.pipe(gulp.dest(bulidPath.skins));
gulp.src([srcPath.skins+'/icons/**'])
.pipe(gulp.dest(bulidPath.skins+'/icons'));
});
//webpack 处理
gulp.task('webpack',function(done){
return gulp.src(srcPath.module+'/**/*')
.pipe(gulpWebpack(webpackConfig))
.pipe(gulp.dest(srcPath.js))
.pipe(connect.reload());
});
gulp.task('clean', function () {
gulp.src([
bulidPath.bulid,
//srcPath.js+'/skins/*.css',srcPath.js+'/skins/*.map',
srcPath.js+'/*.js',srcPath.js+'/*.map',
'!'+srcPath.js+'/jquery.min.js',
'!'+srcPath.js+'/jquery.min.js'
]).pipe(clean());
});
gulp.task('watch', function (done) {
gulp.watch(srcPath.sass +'/**/*.scss',['sass']);
gulp.watch(srcPath.app+'/*.html',['html']);
gulp.watch(srcPath.module+'/**/*',['webpack']);
//gulp.watch(srcPath.js+'/**/*');
});
//启动静态服务器
gulp.task('connect', function () {
connect.server({
root: host.path,
port: host.port,
livereload: true
});
});
gulp.task('open', function () {
gulp.src('')
.pipe(gulpOpen({
app: browser,
uri: host.url
}));
});
//开发
//gulp.task('dev', ['connect','sass','webpack','open'],function(){
gulp.task('dev', ['connect','sass','webpack'],function(){
gulp.start(['watch']);
//gulp.start(['open']);
});
//发布
gulp.task('copy:bulid', ['copy:skins','copy:html','jsmin']);
gulp.task('default',['dev'],function(){
gulp.start(['copy:bulid']);
});