提交 f6d56549 编写于 作者: NoSubject's avatar NoSubject

前端打包增加sourceMap

上级 de105d10
......@@ -14,13 +14,14 @@ var gulp = require('gulp'),
changed = require('gulp-changed'),
gulpif = require('gulp-if'),
http = require('http');
concat = require('gulp-concat');
concat = require('gulp-concat');
var fg = require('fast-glob');
var logger = require('gulp-logger');
var assetRev = require('gulp-tm-asset-rev');
const os = require('os');
var through2 = require('through2');
var path = require('path');
var sourceMap = require('gulp-sourcemaps');
//var downloadHost = "download.o2oa.net";
// var downloadHost = "release.o2oa.net";
......@@ -114,49 +115,49 @@ function downloadFile_progress(path, filename, headcb, progresscb, cb){
// progresscb({transferred:1});
// cb();
// }else{
let stream = fs.createWriteStream(dest);
var options = { url:protocol+"://"+downloadHost+path };
var fileHost = downloadHost;
var filePath = path;
stream.on('finish', () => {
//gutil.log("download", ":", gutil.colors.green(filename), " completed!");
cb();
});
stream.on('error', (err) => {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
let stream = fs.createWriteStream(dest);
var options = { url:protocol+"://"+downloadHost+path };
var fileHost = downloadHost;
var filePath = path;
stream.on('finish', () => {
//gutil.log("download", ":", gutil.colors.green(filename), " completed!");
cb();
});
stream.on('error', (err) => {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
});
var req = http.request({
host:fileHost,
path:filePath,
method:'HEAD'
},function (res){
if (res.statusCode == 200) {
res.setEncoding(null);
var time = 0;
var l = res.headers['content-length'];
var str = progress({
length: l,
time: 100 /* ms */
});
headcb(l);
var req = http.request({
host:fileHost,
path:filePath,
method:'HEAD'
},function (res){
if (res.statusCode == 200) {
res.setEncoding(null);
var time = 0;
var l = res.headers['content-length'];
var str = progress({
length: l,
time: 100 /* ms */
});
headcb(l);
str.on('progress', function(progress) {
if (pb){
progresscb(progress);
pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
}
});
request.get(options).pipe(str).pipe(stream);
} else {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
str.on('progress', function(progress) {
if (pb){
progresscb(progress);
pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
}
})
req.on('error', (e) => {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
});
req.end();
request.get(options).pipe(str).pipe(stream);
} else {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
}
})
req.on('error', (e) => {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
});
req.end();
// }
//});
}
......@@ -203,7 +204,7 @@ function downloadFile(path, filename, headcb, progresscb, cb){
// }
//
// });
request.get(options).pipe(stream);
request.get(options).pipe(stream);
// } else {
// gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
// }
......@@ -285,11 +286,11 @@ function decompress_commons_and_jvm(cb){
src: 'o2server/commons_git.tar.gz',
dest: 'o2server',
tar: {map: function(header){
count++;
count++;
var d = new Date();
slog("["+dateFormat(d, "HH:MM:ss")+"] " + count +" "+ header.name+" ...");
//gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
}}
//gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
}}
}, function(err){
if(err) {
gutil.log(gutil.colors.red("decompress error"), ":", gutil.colors.red("common.tar.gz "), err);
......@@ -414,10 +415,13 @@ function build_concat_o2(){
];
var dest = 'target/o2server/servers/webServer/o2_core/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('o2.js'))
.pipe(gulp.dest(dest))
.pipe(concat('o2.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest))
}
function build_concat_desktop(){
......@@ -441,10 +445,13 @@ function build_concat_desktop(){
];
var dest = 'target/o2server/servers/webServer/o2_core/o2/xDesktop/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('$all.js'))
.pipe(gulp.dest(dest))
.pipe(concat('$all.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest))
}
function build_concat_xform(){
......@@ -471,10 +478,13 @@ function build_concat_xform(){
];
var dest = 'target/o2server/servers/webServer/'+path+'/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('$all.js'))
.pipe(gulp.dest(dest))
.pipe(concat('$all.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest))
}
......@@ -489,10 +499,13 @@ function build_bundle(){
];
var dest = 'target/o2server/servers/webServer/'+path+'/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('bundle.js'))
.pipe(gulp.dest(dest))
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest))
}
......@@ -642,10 +655,13 @@ function build_concat_basework_body() {
];
var dest = 'target/o2server/servers/webServer/x_desktop/js/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('base_work.js'))
.pipe(gulp.dest(dest))
.pipe(concat('base_work.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest));
}
......@@ -743,10 +759,13 @@ function build_concat_baseportal_body() {
];
var dest = 'target/o2server/servers/webServer/x_desktop/js/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('base_portal.js'))
.pipe(gulp.dest(dest))
.pipe(concat('base_portal.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulp.dest(dest));
}
......
......@@ -12,10 +12,11 @@ var gulp = require('gulp'),
JSFtp = require('jsftp'),
gutil = require('gulp-util'),
fs = require("fs");
concat = require('gulp-concat');
concat = require('gulp-concat');
//let uglify = require('gulp-uglify-es').default;
var through2 = require('through2');
var path = require('path');
var sourceMap = require('gulp-sourcemaps');
var assetRev = require('gulp-tm-asset-rev');
......@@ -165,6 +166,7 @@ function createXFormConcatTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('$all.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -182,8 +184,9 @@ function createXFormConcatTask(path, isMin, thisOptions) {
remotePath: (option.remotePath || '/') + path
})))
.pipe(gulp.dest(dest))
.pipe(concat('$all.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
host: option.host,
......@@ -213,6 +216,7 @@ function createO2ConcatTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('o2.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -230,8 +234,10 @@ function createO2ConcatTask(path, isMin, thisOptions) {
remotePath: (option.remotePath || '/') + path
})))
.pipe(gulp.dest(dest))
.pipe(concat('o2.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
host: option.host,
......@@ -271,6 +277,7 @@ function createO2ConcatTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/o2/xDesktop/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('$all.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -288,8 +295,10 @@ function createO2ConcatTask(path, isMin, thisOptions) {
remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
})))
.pipe(gulp.dest(dest))
.pipe(concat('$all.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
host: option.host,
......@@ -319,6 +328,7 @@ function createO2ConcatTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('bundle.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -336,8 +346,10 @@ function createO2ConcatTask(path, isMin, thisOptions) {
remotePath: (option.remotePath || '/') + path
})))
.pipe(gulp.dest(dest))
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(rename({ extname: '.min.js' }))
.pipe(sourceMap.write(""))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
host: option.host,
......@@ -506,6 +518,7 @@ function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('js/base_work.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -523,8 +536,10 @@ function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
remotePath: (option.remotePath || '/') + path
})))
.pipe(gulp.dest(dest))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(concat('js/base_work.min.js'))
.pipe( sourceMap.write("") )
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
host: option.host,
......@@ -652,6 +667,7 @@ function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
];
var dest = option.dest+'/' + path + '/';
return gulp.src(src)
.pipe(sourceMap.init())
.pipe(concat('js/base_portal.js'))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......@@ -672,6 +688,7 @@ function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
// .pipe(gulp.src(src))
.pipe(concat('js/base_portal.min.js'))
.pipe(uglify())
.pipe( sourceMap.write("") )
// .pipe(rename({ extname: '.min.js' }))
.pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
.pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
......
......@@ -40,6 +40,7 @@
"gulp-uglify-es": "^2.0.0",
"merge-stream": "^1.0.1",
"minimist": "^1.2.0",
"readline-sync": "^1.4.10"
"readline-sync": "^1.4.10",
"gulp-sourcemaps": "^3.0.0"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册