gulpfile.js
5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 获取依赖
const childProcess = require('child_process');
const electron = require('electron-prebuilt');
//代码压缩
const gulp = require('gulp');
const gulpLoadPlugins = require( "gulp-load-plugins");
const plugins = gulpLoadPlugins();
const cleanCss = require('gulp-clean-css');
const path= "./app";
const outPutPath= "./app";
const demoName="app";
//版本控制
var bootstrapCssVersion = "1.0.0";
var xnCommonVersion="1.1.7";
var xnFormVersion="1.0.5";
var xnCalendarVersion="1.0.9";
var xnLocationVersion="1.3.1";
var xnSelectVersion="1.3.1";
var loadingVersion="0.0.2";
//压缩依赖进来的js文件路径 build-global-js
var buildBaseFiles = [
"./app/vender/base/jquery.js",
"./app/vender/base/angular.js",
"./app/vender/base/bootstraptpls.js",
"./app/vender/base/browser.js",
"./app/vender/base/method.js",
"./app/vender/base/underscore.js"
];
//压缩依赖进来的js文件路径 build-global-js
var buildGlobalFiles = [
"./spm_modules/xn-common/" + xnCommonVersion + "/directive/commons.js",
"./spm_modules/xn-directive-form/" + xnFormVersion + "/directive/forms.js",
"./spm_modules/xn-directive-calendar/" + xnCalendarVersion + "/directive/calendars.js",
"./spm_modules/xn-directive-location/" + xnLocationVersion + "/directive/locations.js",
"./spm_modules/xn-directive-select/" + xnSelectVersion + "/directive/selects.js",
"./spm_modules/xn-directive-loading/" + loadingVersion + "/directive/nprogress.js",
"./spm_modules/xn-directive-loading/" + loadingVersion + "/directive/loading.js"
];
//指令里的css
var buildGlobalCssFiles = [
"./spm_modules/bootstrap-css/" + bootstrapCssVersion + "/bootstrap.css",
"./spm_modules/xn-common/" + xnCommonVersion + "/directive/style.css",
"./spm_modules/xn-directive-calendar/" + xnCalendarVersion + "/directive/style.css",
"./spm_modules/xn-directive-location/" + xnLocationVersion + "/directive/style.css",
"./spm_modules/xn-directive-select/" + xnSelectVersion + "/directive/style.css",
"./spm_modules/xn-directive-select/" + loadingVersion + "/directive/style.css"
];
//图片处理
var copyCssImagesFiles = [
"./spm_modules/xn-directive-select/" + xnSelectVersion + "/directive/images/*"
];
//字体
var fontFiles = [
"spm_modules/bootstrap-css/" + bootstrapCssVersion + "/font/glyphicons-halflings-regular.eot",
"spm_modules/bootstrap-css/" + bootstrapCssVersion + "/font/glyphicons-halflings-regular.ttf",
"spm_modules/bootstrap-css/" + bootstrapCssVersion + "/font/glyphicons-halflings-regular.woff",
"spm_modules/bootstrap-css/" + bootstrapCssVersion + "/font/glyphicons-halflings-regular.svg"
];
///////////////////////////////////////////////////////////////////////////////////////////////////////版本公共的js
// 合并,压缩指令,过滤器,服务等js到common.min.js
gulp.task("build-base-js", function () {
gulp.src(buildBaseFiles)
.pipe(plugins.concat("base.src.js"))
.pipe(plugins.uglify())
.pipe(plugins.rename("base.min.js"))
.pipe(gulp.dest(outPutPath+"/dist/scripts/"))
.pipe(plugins.gzip())
.pipe(gulp.dest(outPutPath+"/dist/scripts/"));
console.log(buildGlobalFiles);
});
// 合并,压缩指令,过滤器,服务等js到common.min.js
gulp.task("build-global-js", function () {
gulp.src(buildGlobalFiles)
.pipe(plugins.concat("global.src.js"))
.pipe(plugins.uglify())
.pipe(plugins.rename("global.min.js"))
.pipe(gulp.dest(outPutPath+"/dist/scripts/"))
.pipe(plugins.gzip())
.pipe(gulp.dest(outPutPath+"/dist/scripts/"));
console.log(buildGlobalFiles);
});
// css合并,压缩文件
gulp.task("build-global-css", function () {
gulp.src(buildGlobalCssFiles)
.pipe(plugins.concat("global.src.css"))
.pipe(cleanCss({compatibility:"ie8"}))
.pipe(plugins.rename("global.min.css"))
.pipe(gulp.dest(outPutPath+"/dist/styles/"))
.pipe(plugins.gzip())
.pipe(gulp.dest(outPutPath+"/dist/styles/"));
});
//清除js样式
gulp.task("clean-local-js", function () {
gulp.src(path+"/dist/**/local.min.js", {read: false})
.pipe(plugins.clean());
});
//清除css样式
gulp.task("clean-local-css", function () {
gulp.src(path+"/dist/**/local.min.css", {read: false})
.pipe(plugins.clean());
});
// 图片处理
gulp.task('copy-css-images', function () {
gulp.src(copyCssImagesFiles)
.pipe(gulp.dest(outPutPath+"/dist/styles/images/"));
});
// 字体xn-icon
gulp.task('copy-font', function () {
gulp.src(fontFiles)
.pipe(gulp.dest(outPutPath+"/dist/styles/font/"));
});
// 定义develop任务在日常开发中使用
gulp.task("dev", ["build-base-js","build-global-js","build-global-css","copy-font","copy-css-images"], function () {
console.log("运行完成dev");
});
// gulp命令默认启动的就是default认为,这里将clean任务作为依赖,也就是先执行一次clean任务,流程再继续.
gulp.task("default", ["run"], function () {
});
// 创建 gulp run 启动任务
gulp.task('run', function () {
console.log(path);
var process = childProcess.spawn(electron, [path]);//, { stdio: 'inherit' }
// 捕获标准输出并将其打印到控制台
process.stdout.on('data', function (data) {
console.log('标准输出:' + data);
});
// 捕获标准错误输出并将其打印到控制台
process.stderr.on('data', function (data) {
console.log('标准错误输出:' + data);
});
});