gulp生成发布包脚本
var formPost = require('./tools/submit.js');
var gulp = require('gulp'),
zip = require('gulp-zip'),
htmlmin = require('gulp-htmlmin'),
cssmin = require('gulp-minify-css'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
uglify = require('gulp-uglify'),
clean = require('gulp-clean');
cache = require('gulp-cache'),
replace = require('gulp-replace');
minimist = require('minimist'),
gulpif = require('gulp-if'),
stripDebug = require('gulp-strip-debug'),
gulpSequence = require('gulp-sequence'),
rev = require('gulp-rev'),
del = require('del'),
vinylPaths = require('vinyl-paths'),
rename = require('gulp-rename'),
//browserSync = require('browser-sync'),
revCollector = require('gulp-rev-collector'); var configInfo = require("./tools/config_develop.json");
var platformType = {
DEVELOP:1,
TEST:2,
PUBLISH:3
}; var knownOptions = {
number: ['ver',"env"],
default: {
ver: '0.2.0',
env:platformType.DEVELOP
}
};
var processoptions = minimist(process.argv.slice(2), knownOptions);
var zipFileName = function(){
return 'html5_'+configInfo.name +"_"+ processoptions.ver+'.zip';
};
gulp.task("clean", function(){
return gulp.src([configInfo.targetdirectory])
.pipe(clean());
}); gulp.task('minify:html', function () {
var options = {
removeComments: true,//清除HTML注释
collapseWhitespace: true,//压缩HTML
collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
minifyJS: true,//压缩页面JS
minifyCSS: true//压缩页面CSS
};
return gulp.src(['html/*.html', 'index.html', 'error404.html'],{ base: "." })
// .pipe(stripDebug())
.pipe(htmlmin(options))
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('minify:css', function () {
return gulp.src(['css/*.css','!css/mui.css'])
.pipe(cssmin())
.pipe(gulp.dest(configInfo.targetdirectorywww + 'css'));
}); gulp.task('minify:image', function () {
return gulp.src(['img/*.{png,jpg,gif}', "img/**/*.{png,jpg,gif}"])
.pipe(imagemin({
// use: [pngquant({quality: '65-80'})],
optimizationLevel: 5, //类型:Number 默认:3 取值范围:0-7(优化等级)
progressive: true, //类型:Boolean 默认:false 无损压缩jpg图片
interlaced: true, //类型:Boolean 默认:false 隔行扫描gif进行渲染
multipass: true ,//类型:Boolean 默认:false 多次优化svg直到完全优化
use: [pngquant()],
}))
.pipe(gulp.dest(configInfo.targetdirectorywww + 'img'));
}); gulp.task('minify:js', function () {
return gulp.src(['js/*.js', 'js/**/*.js', '!js/config.js', '!js/libs/mui.js'])
.pipe(stripDebug())
.pipe(uglify({
// mangle: true,//类型:Boolean 默认:true 是否修改变量名
// mangle: {except: ['require' ,'exports' ,'module' ,'$']}//排除混淆关键字
// compress: true,//类型:Boolean 默认:true 是否完全压缩
// preserveComments: 'all' //保留所有注释
}))
.pipe(gulp.dest(configInfo.targetdirectorywww + 'js'));
}); gulp.task('copy:files', function () {
return gulp.src(['manifest.json', "fonts/**", "!fonts/iconfont.ttf"], {base: "."})
.pipe(gulp.dest(configInfo.targetdirectorywww));
});
gulp.task('copy:filesall', function(){
return gulp.src(['js/**/*','!js/config.js','html/*.html','css/*','img/**/*','index.html',"error404.html",'manifest.json', "fonts/**"], {base: "."})
.pipe(gulp.dest(configInfo.targetdirectorywww));
});
gulp.task('replace:dev', function () {
return gulp.src(["js/config.js"])
.pipe(gulp.dest(configInfo.targetdirectorywww + "js"));
});
gulp.task('replace:test', function () {
return gulp.src(["js/config.js"])
.pipe(uglify())
.pipe(replace(new RegExp(/IP:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP:"http://172.18.0.6/"'))
.pipe(replace(new RegExp(/IP_CHAT:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP_CHAT:"http://172.18.0.6/"'))
.pipe(replace(new RegExp(/IP_FILE:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP_FILE:"http://172.18.0.6/"'))
.pipe(replace(new RegExp(/,CHAT:"shengqi-api\/chat\/"/), ',CHAT:"chat/"'))
.pipe(gulp.dest(configInfo.targetdirectorywww + "js"));
}); gulp.task('replace:publish', function () {
return gulp.src(["js/config.js"])
.pipe(uglify())
.pipe(replace(new RegExp(/IP:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP:"http://sqapp.miligames.com/"'))
.pipe(replace(new RegExp(/IP_CHAT:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP_CHAT:"http://sqapp.miligames.com/"'))
.pipe(replace(new RegExp(/IP_FILE:"(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?"/), 'IP_FILE:"http://sqapp.miligames.com/"'))
.pipe(replace(new RegExp(/,CHAT:"shengqi-api\/chat\/"/), ',CHAT:"chat/"'))
.pipe(gulp.dest(configInfo.targetdirectorywww + "js"));
}); gulp.task('build:version', function(){
return gulp.src(["version.txt"])
.pipe(replace(new RegExp(/.*/), processoptions.ver))
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('upload', function(){
formPost.postFormInfo(configInfo.uploadip, processoptions.ver,configInfo.targetzip + "/"+zipFileName(), configInfo);
}); gulp.task('archive', function () {
return gulp.src(configInfo.targetdirectory + '**')
.pipe(zip(zipFileName()))
.pipe(gulp.dest(configInfo.targetzip));
}); gulp.task('build:dev', gulpSequence(["clean"], ['copy:filesall', "build:version", "replace:dev"], ["archive"], ["upload"]));
//gulp.task('build:test', gulpSequence(["clean"], ["minify:html", 'minify:css','minify:js','minify:image','copy:files', 'replace:test',"build:version"], ["archive"], ["upload"]));
gulp.task('build:test', gulpSequence(["clean"], ['copy:filesall', 'replace:test',"build:version"], ["archive"], ["upload"]));
gulp.task('build:publish', gulpSequence(["clean"], ["minify:html", 'minify:css','minify:js','minify:image','copy:files', 'replace:publish',"build:version"], ["archive"], ["upload"])); gulp.task("app-build", function(){
switch (processoptions.env) {
case platformType.DEVELOP:
configInfo = require("./tools/config_develop.json");
//gulp.start("build:dev");
gulp.start("b:dev");
break;
case platformType.TEST:
configInfo = require("./tools/config_test.json");
//gulp.start("build:test");
gulp.start("b:test");
break;
case platformType.PUBLISH:
configInfo = require("./tools/config_publish.json");
//gulp.start("build:publish");
gulp.start("b:publish");
break;
}
});
//=========================================================================================================
var cssSrc = 'css/**/app*.css'; gulp.task('mfy:image', function () {
return gulp.src(['img/*.{png,jpg,gif}', "img/**/*.{png,jpg,gif}"])
.pipe(imagemin({
// use: [pngquant({quality: '65-80'})],
optimizationLevel: 5, //类型:Number 默认:3 取值范围:0-7(优化等级)
progressive: true, //类型:Boolean 默认:false 无损压缩jpg图片
interlaced: true, //类型:Boolean 默认:false 隔行扫描gif进行渲染
multipass: true ,//类型:Boolean 默认:false 多次优化svg直到完全优化
use: [pngquant()],
}))
.pipe(gulp.dest(configInfo.targetdirectorywww + 'img'));
}); gulp.task('css_rev', function() {
return gulp.src([cssSrc, 'css/im_chat.css', '!css/mui*.css'])
.pipe(rename(function (path) {
//path.basename += ".min";
path.extname = ".css"
}))
.pipe(rev())
.pipe(gulpif(processoptions.env == platformType.PUBLISH, cssmin()))
.pipe(gulp.dest("css2"))
.pipe(rev.manifest())
.pipe(gulp.dest("rev/css"));
}); gulp.task('js_rev', function() {
return gulp.src(['js/*.js', 'js/**/*.js', '!js/cursormanager.js', '!js/config.js', '!js/libs/*.js'], {base: "."})
.pipe(rename(function (path) {
//path.basename += ".min";
path.extname = ".js"
}))
.pipe(rev())
.pipe(gulpif(processoptions.env == platformType.PUBLISH, uglify({})))
.pipe(gulp.dest("js2"))
.pipe(rev.manifest())
.pipe(gulp.dest("rev/js"));
}); gulp.task('replace_js_rev', ['replace_css_rev', 'js_rev'], function() {
gulp.src(["rev/js/**/*.json", 'html2/*.html'])
.pipe(revCollector({
replaceReved: true
}))
.pipe(gulp.dest("html3")); return gulp.src(["rev/js/**/*.json", 'html2/html/*.html'])
.pipe(revCollector({
replaceReved: true
}))
.pipe(gulp.dest("html3/html"));
}); gulp.task('replace_css_rev', ['css_rev'], function() {
gulp.src(["rev/css/**/*.json", '*.html'])
.pipe(revCollector({
replaceReved: true
}))
.pipe(gulp.dest("html2")); return gulp.src(["rev/css/**/*.json", 'html/*.html'])
.pipe(revCollector({
replaceReved: true
}))
.pipe(gulp.dest("html2/html"));
}); gulp.task('cp:html', ['replace_js_rev'], function() {
var options = {
removeComments: true,//清除HTML注释
collapseWhitespace: true,//压缩HTML
collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
minifyJS: true,//压缩页面JS
minifyCSS: true//压缩页面CSS
}; gulp.src(['html3/html/*.html'], {base: "."})
.pipe(rename({dirname: ''})).pipe(gulpif(processoptions.env == platformType.PUBLISH, htmlmin(options)))
.pipe(gulp.dest(configInfo.targetdirectorywww + "html")); return gulp.src(['html3/*.html'])
.pipe(rename({dirname: ''})).pipe(gulpif(processoptions.env == platformType.PUBLISH, htmlmin(options)))
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('cp:files', ['cp:reved_css','replace_css_rev'], function () {
return gulp.src(['manifest.json', 'css/mui*.css', "fonts/**", "!fonts/iconfont.ttf"], {base: "."})
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('cp:filesall', ['cp:reved_css','replace_css_rev'], function(){
return gulp.src(['!js/config.js','css/mui*.css','img/**/*',"error404.html",'manifest.json', "fonts/**"], {base: "."})
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('cp:unreved_js', ['js_rev'], function () {
gulp.src(['js/libs/*.js'])
.pipe(stripDebug())
.pipe(gulpif(processoptions.env == platformType.PUBLISH, uglify({})))
.pipe(gulp.dest(configInfo.targetdirectorywww + 'js/libs')); return gulp.src(['js/cursormanager.js'])
.pipe(stripDebug())
.pipe(gulpif(processoptions.env == platformType.PUBLISH, uglify({})))
.pipe(gulp.dest(configInfo.targetdirectorywww + 'js'));
}); gulp.task('cp:reved_js', ['js_rev'], function() {
return gulp.src(['js2/**/*.js'])
.pipe(gulp.dest(configInfo.targetdirectorywww));
}); gulp.task('cp:reved_css', ['css_rev'], function() {
return gulp.src(['css2/*'])
.pipe(rename({dirname: ''}))
.pipe(gulp.dest(configInfo.targetdirectorywww + "css/"));
}); gulp.task("cl:tmp", function(){
//gulp.src([configInfo.targetdirectorywww + "html/*.html"]).pipe(vinylPaths(del));
return gulp.src(['js2','css2','html2', 'html3', 'rev'])
.pipe(clean());
}); gulp.task('b:dev', gulpSequence(["clean"], ['cp:filesall', 'cp:unreved_js','cp:html', 'cp:reved_js', "build:version", "replace:dev"], ["archive"], ["upload"],['cl:tmp']));
gulp.task('b:publish', gulpSequence(["clean"], ['cp:unreved_js','cp:html','cp:reved_js','mfy:image','cp:files', 'replace:publish',"build:version"], ["archive"],['cl:tmp']));
gulp.task('b:test', gulpSequence(["clean"], ['cp:filesall', 'cp:unreved_js','cp:html', 'cp:reved_js', 'replace:test',"build:version"], ["archive"],["upload"],['cl:tmp'])); //gulp.task('browser-sync', function () {
// var files = [
// './**/*.html',
// './css/**/*.css',
// './imgs/**/*.png',
// './js/**/*.js'
// ]; // browserSync.init(files, {
// server: {
// baseDir: './'
// }
// });
//});
gulp生成发布包脚本的更多相关文章
- 给ASP.NET Core Web发布包做减法
1.引言 紧接上篇:ASP.NET Core Web App应用第三方Bootstrap模板.这一节我们来讲讲如何优化ASP.NET Core Web发布包繁重的问题. 在ASP.NET Core W ...
- 给控件做数字签名之一:将控件打包为Web发布包 [转]
微软代码签名证书使用指南 http://www.wotrust.com/support/signcode_guide.htm 签名重要性:http://www.wotrust.com/FAQ/whyS ...
- NET Core Web发布包
给ASP.NET Core Web发布包做减法 https://www.cnblogs.com/sheng-jie/p/9122582.html 1.引言 紧接上篇:ASP.NET Core Web ...
- Flutter:发布包
[package] 生成包含模块化Dart代码的可共享Flutter项目 [plugin] 生成一个可共享的Flutter项目, 在Dart代码中包含带有API的API, 针对Android的平台特定 ...
- npm ERR publish 403,nodejs发布包流程
nodejs学习体验之发布包,发布环境如下:1:win10系统,2:已安装nodejs. 具体操作步骤如下: *编写模块 1)新建文件夹,比如:somepackage 2) 该文件夹下新建js文件,比 ...
- Gulp解决发布线上文件(CSS和JS)缓存问题
Gulp解决发布线上文件(CSS和JS)缓存问题 本文的缘由:目前经常线上发布文件后要不断的刷新页面及过很长时间,页面上的CSS和JS文件才能生效,特别对于目前做微信商城的时候,微信内置的浏览器缓存非 ...
- npm发布包--所遇到的问题
npm发布包: 解决方案--npm adduser的坑:http://www.tuicool.com/articles/FZbYve npm ERR publish 403,nodejs发布包流程 : ...
- python发布包到pypi的踩坑记录
前言 突然想玩玩python了^_^ 这篇博文记录了我打算发布包到pypi的踩坑经历.python更新太快了,甚至连这种发布上传机制都在不断的更新,这导致网上的一些关于python发布上传到pypi的 ...
- npm学习(七)之如何发布包、更新发布包、删除发布包
前言 我们经常使用npm来下载别人的模块或者说包,那么我们如何将自己写的模块上传到npm呢? 了解npm政策 在开始之前,最好回顾一下npm的政策,以防您对站点礼仪.命名.许可或其他指导原则有疑问. ...
随机推荐
- win 10中打开sql server配置管理器
转自: https://www.cnblogs.com/He-tao-yuan/p/6744412.html
- Mac mysql 解决中文乱码
Mac mysql 解决中文乱码问题 出现"???"之类的无法识别的乱码 到/etc目录下自己建一个my.cnf文件(需要最高权限,使用sudo su),然后写入内容: [clie ...
- Tomcat域名绑定
域名绑定与虚拟目录设置: conf/server.xml 的修改方式如下: 单个域名绑定: 原始: <Engine name="Catalina" defaultHost=& ...
- SVN中图标符号的含义
黄色感叹号(有冲突): 这是有冲突了,冲突就是说你对某个文件进行了修改,别人也对这个文件进行了修改,别人抢在你提交之前先提交了,这时你再提交就会被提示发生冲突,而不允许你提交,防止你的提交覆盖了别人的 ...
- asp.net c# repeater或gridview导出EXCEL的详细代码。
Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Enco ...
- 安卓开发笔记——Menu菜单组件(选项菜单,上下文菜单,子菜单)
菜单是用户界面中最常见的元素之一,使用非常频繁,在Android中,菜单被分为如下三种,选项菜单(OptionsMenu).上下文菜单(ContextMenu)和子菜单(SubMenu). 菜单的实现 ...
- 周期性调度器scheduler_tick
周期性调度器由中断实现,系统定时产生一个中断,然后启动周期性调度器,周期性调度器执行过程中要关闭中断, 周期性调度器执行完毕后再打开中断(handle_IRQ_event, IRQF_DISABLE ...
- python 数据类型-字符串-对象和方法
python的字符串有众多方法,可以在doc文档中查看 示例 转换开头字母为大写 c1="welcome to my python" >>> c1.capital ...
- mysql 用户权限操作
https://www.cnblogs.com/SQL888/p/5748824.html http://blog.csdn.net/fafa211/article/details/2249217
- [原]pomelo开发环境搭建
pomelo基于nodejs服务器开源框架,比较牛逼的! 1.安装nodejs(官网下载地址) 安装python等 具体见官网说明 2.安装pomelo(见官方步骤)或者 http://blog.cs ...