Skip to content

Commit f864d13

Browse files
author
tower1229
committed
code clear
1 parent f9516cf commit f864d13

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

bin/build.js

+29-15
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const cssNormalOut = function(option) {
175175
// compress:
176176
// callback
177177
// }
178-
if (!option || !option.src || !option.dest.split) {
178+
if (!option || !option.src || !option.dest || !option.dest.split) {
179179
return console.log('cssNormalOut()参数错误!');
180180
}
181181
if (!option.mapsrc) {
@@ -214,6 +214,26 @@ const cssNormalOut = function(option) {
214214
});
215215
};
216216

217+
const imageMin = function(option){
218+
// {
219+
// src:
220+
// dest:
221+
// callback
222+
// }
223+
if (!option || !option.src || !option.dest || !option.dest.split) {
224+
return console.log('imageMin()参数错误!');
225+
}
226+
gulp.src(option.src)
227+
.pipe(changed(option.dest))
228+
.pipe(imagemin())
229+
.pipe(gulp.dest(option.dest))
230+
.on('end', function() {
231+
if (typeof(option.callback) === 'function') {
232+
option.callback();
233+
}
234+
});
235+
};
236+
217237
const scriptLib = function(filePath, callback) {
218238
if (!globalConfig.compress) {
219239
scriptsNormalOut({
@@ -283,20 +303,14 @@ let script = function(filePath, callback) {
283303
script.prototype.todoList = [scriptLib, scriptApp];
284304

285305
let image = function(filePath, callback) {
286-
gulp.src(globalConfig.paths.imageALL)
287-
.pipe(changed(globalConfig.distDir))
288-
.pipe(imagemin())
289-
.pipe(gulp.dest(globalConfig.distDir));
290-
291-
gulp.src(globalConfig.paths.image)
292-
.pipe(changed(globalConfig.dist.img))
293-
.pipe(imagemin())
294-
.pipe(gulp.dest(globalConfig.dist.img))
295-
.on('end', function() {
296-
if (typeof(callback) === 'function') {
297-
callback();
298-
}
299-
});
306+
if(!filePath){
307+
filePath = globalConfig.paths.imageAll;
308+
}
309+
imageMin({
310+
src: filePath,
311+
dest: globalConfig.distDir,
312+
callback: callback
313+
});
300314
};
301315

302316
let font = function(file, callback) {

bin/paths.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const getPath = function() {
2323
scriptConcat: [path.join(userConfig.projectDir, '/lib/seajs/sea.js'), globalConfig.compress ? path.join(userConfig.projectDir, '/seajs.config.js') : '', path.join(userConfig.projectDir, '/lib/seajs/manifest.js'), path.join(userConfig.projectDir, '/lib/seajs/seajs-localcache.js')],
2424
scriptApp: [path.join(userConfig.projectDir, '/js/*.{' + types.script + '}')],
2525
scriptLib: [path.join(userConfig.projectDir, '/lib/**'), '!' + path.join(userConfig.projectDir, '/lib/seajs/**')],
26-
image: [path.join(userConfig.projectDir, '/img/**/*.{' + types.img + '}')],
27-
imageALL: [path.join(userConfig.projectDir, '/**/*.{' + types.img + '}'), '!' + path.join(userConfig.projectDir, '/img/**/*.{' + types.img + '}')],
26+
imageAll: [path.join(userConfig.projectDir, '/**/*.{' + types.img + '}')],
2827
cssMain: ['/css/style.less', '/css/resp-smal.less', '/css/resp-midd.less', '/css/config.less', '/css/responsive.less', '_component/'],
2928
cssMainTarget: path.join(globalConfig.projectDir, '/css/style.less'),
3029
cssOther: [path.join(userConfig.projectDir, '/**/*.{' + types.css + '}'), '!' + path.join(userConfig.projectDir, '/include/**'), '!' + path.join(userConfig.projectDir, '/css/style.less'), '!' + path.join(userConfig.projectDir, '/css/resp-smal.less'), '!' + path.join(userConfig.projectDir, '/css/resp-midd.less'), '!' + path.join(userConfig.projectDir, '/css/config.less'), '!' + path.join(userConfig.projectDir, '/css/responsive.less')],
@@ -39,7 +38,7 @@ const getPath = function() {
3938
css: path.join(userConfig.distDir, './css'),
4039
font: path.join(userConfig.distDir, './font'),
4140
img: path.join(userConfig.distDir, './img'),
42-
html: path.join(userConfig.distDir)
41+
html: path.join(userConfig.distDir, './')
4342
};
4443
return globalConfig;
4544
} else {

0 commit comments

Comments
 (0)