-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
210 lines (180 loc) · 5.62 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const gulp = require('gulp'),
path = require('path'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
// rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
cache = require('gulp-cache'),
plumber = require('gulp-plumber'),
nunjucksRender = require('gulp-nunjucks-render'),
data = require('gulp-data'),
browserSync = require('browser-sync').create(),
babel = require('gulp-babel'),
// runSequence = require('run-sequence'),
md5 = require("gulp-md5-plus"),
reload = browserSync.reload
// 清理
gulp.task('clean', function() {
return gulp.src(['dist'], { read: false }).pipe(clean());
});
function getDataForFile(file) {
return {
mock: require('./src/mock/' + path.basename(file.path, '.html') + '.json')
};
}
// html
gulp.task('html', function (done) {
gulp.src('src/view/**/*.html')
// .pipe(data(getDataForFile))
.pipe(nunjucksRender({
path: ['src/common/', 'src/components/'] // String or Array
}))
.pipe(gulp.dest('dist/view'));
done()
});
// fonts
gulp.task('outfonts', function (done) {
gulp.src('src/fonts/**/*').pipe(gulp.dest('dist/fonts'))
done()
});
gulp.task('fonts', gulp.series('outfonts', function (done) {
gulp.src('src/css/fonts/**/*').pipe(gulp.dest('dist/css/fonts'))
done()
}));
gulp.task('scss', function(done) {
return gulp.src('src/css/**/*.scss')
.pipe(plumber())
.pipe(sass())
.pipe(autoprefixer({
overrideBrowserslist: [
"Android 4.1",
"iOS 7.1",
"Chrome > 31",
"ff > 31",
"ie >= 8"
],
grid: true
}))
.pipe(minifycss())
// .pipe(md5(10, 'dist/view/**/*.html'))
.pipe(gulp.dest('dist/css'))
});
gulp.task('oc_sass', function() {
return gulp.src('src/sass/onecore.scss')
.pipe(plumber())
.pipe(sass())
.pipe(autoprefixer({
overrideBrowserslist: [
"Android 4.1",
"iOS 7.1",
"Chrome > 31",
"ff > 31",
"ie >= 8"
],
grid: true
}))
.pipe(minifycss())
// .pipe(md5(10, 'dist/view/**/*.html'))
.pipe(gulp.dest('dist/css'))
});
// 脚本
gulp.task('scripts', function() {
return gulp.src('src/js/app/**/*.js')
.pipe(babel({
presets: ['env']
}))
// .pipe(uglify())
// .pipe(md5(10, 'dist/view/**/*.html'))
.pipe(gulp.dest('dist/js/app'))
});
// onecore
gulp.task('onecore', function() {
return gulp.src([
'src/js/onecore/bliss.js',
'src/js/onecore/util.js',
'src/js/onecore/area.js',
'src/js/onecore/onecore.js',
'src/js/onecore/msgbox.js',
'src/js/onecore/toast.js',
'src/js/onecore/dropmenu.js',
'src/js/onecore/select.js',
'src/js/onecore/datepicker.js',
'src/js/onecore/page.js',
// 'src/js/onecore/slider.js',
'src/js/onecore/tab.js',
'src/js/onecore/validate.js',
'src/js/onecore/imgup.js',
'src/js/onecore/imgbox.js',
'src/js/onecore/city.js'
// 'src/js/onecore/accordion.js',
// 'src/js/onecore/domark.js'
])
.pipe(plumber())
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat('onecore.js'))
.pipe(uglify())
// .pipe(md5(10, 'dist/view/**/*.html'))
.pipe(gulp.dest('dist/js/lib'))
// .pipe(notify({
// message: 'onecore task complete'
// }));
});
// 脚本
gulp.task('libs', function() {
return gulp.src('src/js/lib/**/*.js')
// .pipe(uglify())
.pipe(gulp.dest('dist/js/lib'))
});
// 图片
gulp.task('images', function() {
return gulp.src('src/img/**/*')
// .pipe(cache(imagemin({
// optimizationLevel: 3,
// progressive: true,
// interlaced: true
// })))
.pipe(gulp.dest('dist/img'))
});
// 看守
gulp.task('watch', function(done) {
gulp.watch('src/css/**/*.scss', gulp.series('scss'));
gulp.watch('src/sass/**/*.scss', gulp.series('oc_sass'));
gulp.watch('src/view/**/*.html', gulp.series('html'));
gulp.watch('src/common/**/*.html', gulp.series('html'));
gulp.watch('src/components/**/*.html', gulp.series('html'));
gulp.watch('src/js/app/**/*.js', gulp.series('scripts'));
gulp.watch('src/js/onecore/**/*.js', gulp.series('onecore'));
gulp.watch('src/js/lib/**/*.js', gulp.series('libs'));
gulp.watch('src/img/**/*', gulp.series('images'));
gulp.watch("dist/css/**/*.css").on('change', reload);
gulp.watch("dist/js/**/*.js").on('change', reload);
gulp.watch("dist/view/**/*.html").on('change', reload);
gulp.watch("dist/img/**/*").on('change', reload);
done()
});
// server
gulp.task('server', function() {
browserSync.init({
port: 3001,
server: {
baseDir: "./dist",
index: "/view/index.html"
}
});
});
// 预设任务1
gulp.task('resetAll', gulp.series('html', 'fonts', 'scss', 'oc_sass', 'scripts', 'onecore', 'libs', function(done) {
condition = false;
done()
}));
// 预设任务
gulp.task('default', gulp.series('resetAll', 'images', 'watch', 'server', function(done) {
condition = false;
done()
}));