Upgrade code
This commit is contained in:
1 parent
4a6bbe93b2
commit
dd6da7e650
5 files changed
+89
-72
No files matched your search
@@ -19,6 +19,8 @@ const lodash = require('lodash');
|
||||
const path = require('path');
|
||||
const plumber = require('gulp-plumber');
|
||||
const notify = require('gulp-notify');
|
||||
const babel = require('gulp-babel');
|
||||
const runSequence = require('run-sequence');
|
||||
|
||||
let swigOpts = {
|
||||
defaults: {
|
||||
@@ -37,21 +39,6 @@ function onErrorHandler(err) {
|
||||
this.emit('end');
|
||||
}
|
||||
|
||||
//代理配置
|
||||
let proxy = proxyMiddleware(
|
||||
['/node_modules','/res/images/userimage'],
|
||||
{
|
||||
//target:'http://172.26.68.35:8085'//
|
||||
target: 'http://node.dengtongyu.com'
|
||||
//target:'http://47.94.23.46:80'
|
||||
}
|
||||
);
|
||||
let proxy2 = proxyMiddleware(
|
||||
['/data/getPictureList'],
|
||||
{
|
||||
target: 'http://localhost:8080'
|
||||
}
|
||||
);
|
||||
|
||||
function pathType(filePath) {
|
||||
let type = path.parse(filePath).ext;
|
||||
@@ -85,18 +72,69 @@ module.exports = function (pathConfig,config) {
|
||||
|
||||
function watcherListFun(watchList) {
|
||||
for (var i = 0; i < watchList.length; i++) {
|
||||
if(watchList[i].taskName[0] == 'uglify_build' || watchList[i].taskName[0] == 'htmlmin_build') continue;
|
||||
|
||||
gulp.watch(watchList[i].watchPath,watchList[i].taskName).on('change', function (event) {
|
||||
let fileType = pathType(event.path);
|
||||
let fileType = pathType(event.path);
|
||||
pathConfig[watchList[fileType].taskPath] = path.relative(__dirname,event.path);
|
||||
//added为新增,deleted为删除,changed为改变
|
||||
//变化类型 和 变化的文件的路径
|
||||
console.log(event.type + ' : ' + pathConfig[watchList[fileType].taskPath]);
|
||||
console.log(event.type + ' : ' + pathConfig[watchList[fileType].taskPath]);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let watchList = [{
|
||||
watchPath:pathConfig.styleBuildPath,
|
||||
taskName:['stylus_build'],
|
||||
taskPath:'styleChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.htmlBuildPath,
|
||||
taskName:['html_build'],
|
||||
taskPath:'swigChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.htmlminBuildPath,
|
||||
taskName:['htmlmin_build'],
|
||||
taskPath:'htmlminChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.scriptBuildPath,
|
||||
taskName:['js_build'],
|
||||
taskPath:'scriptChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.uglifyBuildPath,
|
||||
taskName:['uglify_build'],
|
||||
taskPath:'uglifyChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.tmodBuildPath,
|
||||
taskName:['tmodjs_build'],
|
||||
taskPath:'tmodChangePath'
|
||||
}];
|
||||
|
||||
//server任务
|
||||
gulp.task('server', function () {
|
||||
|
||||
//代理配置
|
||||
let proxy = proxyMiddleware(
|
||||
['/node_modules','/res/images/userimage'],
|
||||
{
|
||||
//target:'http://172.26.68.35:8085'//
|
||||
target: 'http://node.dengtongyu.com'
|
||||
//target:'http://47.94.23.46:80'
|
||||
}
|
||||
);
|
||||
let proxy2 = proxyMiddleware(
|
||||
['/data/getPictureList'],
|
||||
{
|
||||
target: 'http://localhost:8080'
|
||||
}
|
||||
);
|
||||
|
||||
browserSync({
|
||||
host: 'localhost',
|
||||
open: 'external',
|
||||
@@ -107,42 +145,10 @@ module.exports = function (pathConfig,config) {
|
||||
baseDir: 'build',
|
||||
middleware: [proxy,proxy2]
|
||||
}
|
||||
});
|
||||
|
||||
let watchList = [
|
||||
{
|
||||
watchPath:pathConfig.styleBuildPath,
|
||||
taskName:['stylus_build'],
|
||||
taskPath:'styleChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.htmlBuildPath,
|
||||
taskName:['swig_build'],
|
||||
taskPath:'swigChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.htmlminBuildPath,
|
||||
taskName:['htmlmin_build'],
|
||||
taskPath:'htmlminChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.scriptBuildPath,
|
||||
taskName:['webpack_build'],
|
||||
taskPath:'scriptChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.uglifyBuildPath,
|
||||
taskName:['uglify_build'],
|
||||
taskPath:'uglifyChangePath'
|
||||
},
|
||||
{
|
||||
watchPath:pathConfig.tmodBuildPath,
|
||||
taskName:['tmod_build'],
|
||||
taskPath:'tmodChangePath'
|
||||
}
|
||||
]
|
||||
|
||||
watcherListFun(watchList);
|
||||
});
|
||||
|
||||
watcherListFun(watchList);
|
||||
|
||||
});
|
||||
|
||||
//stylus任务
|
||||
@@ -178,9 +184,12 @@ module.exports = function (pathConfig,config) {
|
||||
gulp.task('webpack_build', function () {
|
||||
return gulp.src(pathConfig.scriptBuildPath)
|
||||
.pipe(plumber({errorHandler: onErrorHandler}))
|
||||
.pipe(webpack( webPackConfig ))
|
||||
.pipe(webpack( webPackConfig ))
|
||||
.pipe(babel({
|
||||
presets: ['env']
|
||||
}))
|
||||
.pipe(gulp.dest(pathConfig.webpackOutPath))
|
||||
.on("end", reload);
|
||||
.on("end", reload);
|
||||
});
|
||||
|
||||
//uglify任务
|
||||
@@ -194,7 +203,7 @@ module.exports = function (pathConfig,config) {
|
||||
|
||||
//tmod任务
|
||||
gulp.task('tmod_build', function () {
|
||||
console.log(pathConfig.tmodBuildPath);
|
||||
//console.log(pathConfig.tmodBuildPath);
|
||||
return gulp.src(pathConfig.tmodBuildPath)
|
||||
.pipe(plumber({errorHandler: onErrorHandler}))
|
||||
.pipe(tmodjs({
|
||||
@@ -205,4 +214,20 @@ module.exports = function (pathConfig,config) {
|
||||
}))
|
||||
.on("end", reload);
|
||||
});
|
||||
|
||||
//watch html任务
|
||||
gulp.task('html_build', function () {
|
||||
runSequence('swig_build','htmlmin_build');
|
||||
});
|
||||
|
||||
//watch js任务
|
||||
gulp.task('js_build', function () {
|
||||
//console.log('执行了js_build')
|
||||
runSequence('webpack_build', 'uglify_build');
|
||||
});
|
||||
|
||||
//watch tmodjs任务
|
||||
gulp.task('tmodjs_build', function () {
|
||||
runSequence('tmod_build', 'webpack_build', 'uglify_build');
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user