Upgrade code
This commit is contained in:
1 parent
4a6bbe93b2
commit
dd6da7e650
5 files changed
+89
-72
No files matched your search
@@ -48,15 +48,6 @@ let colorLog = function (text, color) {
|
||||
|
||||
let userInput = 1; //输入值
|
||||
|
||||
gulp.task('server', function() {
|
||||
|
||||
|
||||
});
|
||||
|
||||
gulp.task('build', function (cb) {
|
||||
|
||||
});
|
||||
|
||||
//复制模板
|
||||
gulp.task('copy-pc', function () {
|
||||
return gulp.src(config.base + '/template/tpl-pc/**/*.*')
|
||||
|
||||
+8
-5
@@ -9,18 +9,21 @@
|
||||
"author": "dengtongyu",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"art-template": "^4.12.1",
|
||||
"browser-sync": "^2.18.11",
|
||||
"art-template": "^4.12.2",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"browser-sync": "^2.23.6",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^7.0.1",
|
||||
"gulp-htmlmin": "^3.0.0",
|
||||
"gulp-notify": "^3.2.0",
|
||||
"gulp-plumber": "^1.2.0",
|
||||
"gulp-stylus": "^2.6.0",
|
||||
"gulp-stylus": "^2.7.0",
|
||||
"gulp-swig": "^0.8.0",
|
||||
"gulp-tmod": "^2.0.3",
|
||||
"gulp-uglify": "^2.1.2",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"gulp-webpack": "^1.5.0",
|
||||
"http-proxy-middleware": "^0.17.4",
|
||||
"run-sequence": "^1.2.2"
|
||||
"run-sequence": "^2.2.1"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
@charset "UTF-8";
|
||||
/**
|
||||
*
|
||||
* @authors Tony.Deng (dengtongyu123@163.com)
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
@charset "UTF-8";
|
||||
|
||||
/*!
|
||||
* animate.css -https://daneden.me/animate
|
||||
|
||||
@@ -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