This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathgulpfile.js
139 lines (131 loc) · 3.71 KB
/
gulpfile.js
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
let tmplFolder = 'tmpl'; //template folder
let srcFolder = 'src'; //source folder
let buildFolder = 'build';
let gulp = require('gulp');
let watch = require('gulp-watch');
let del = require('del');
let fs = require('fs');
let ts = require('typescript');
let concat = require('gulp-concat');
let combineTool = require('magix-combine');
combineTool.config({
debug: true,
commonFolder: tmplFolder,
compiledFolder: srcFolder,
cssSelectorPrefix: 'pe-',
loaderType: 'cmd',
md5CssSelectorLen: 3,
addTmplViewsToDependencies: true,
magixUpdaterIncrement: true,
magixTmplFnInside: false,
galleries: {
mxRoot: 'gallery/'
},
scopedCss: [
'./tmpl/gallery/mx-style/index.less',
'./tmpl/editor/assets/index.less'
],
compileTmplCommand(content) {
var str = ts.transpileModule(content, {
compilerOptions: {
lib: ['es7'],
target: 'es3',
module: ts.ModuleKind.None
}
});
str = str.outputText;
return str;
},
compileJSStart(content) {
var str = ts.transpileModule(content, {
compilerOptions: {
lib: ['es7'],
target: 'es3',
module: ts.ModuleKind.None
}
});
str = str.outputText;
return str;
}
});
gulp.task('cleanSrc', () => del(srcFolder));
gulp.task('combine', gulp.series('cleanSrc', () => {
console.time('combine');
return combineTool.combine().then(() => {
console.log('complete');
console.timeEnd('combine');
}).catch(function (ex) {
console.log('gulpfile:', ex);
process.exit();
});
}));
gulp.task('watch', gulp.series('combine', () => {
watch(tmplFolder + '/**/*', e => {
if (fs.existsSync(e.path)) {
var c = combineTool.processFile(e.path);
c.catch(function (ex) {
console.log('ex', ex);
});
} else {
combineTool.removeFile(e.path);
}
});
}));
var uglify = require('gulp-uglify');
gulp.task('cleanBuild', function () {
return del(buildFolder);
});
// gulp.task('build', ['cleanBuild', 'cleanSrc'], function () {
// combineTool.config({
// debug: false
// });
// combineTool.combine().then(() => {
// gulp.src(srcFolder + '/**/*.js')
// .pipe(uglify({
// compress: {
// drop_console: true,
// drop_debugger: true,
// global_defs: {
// DEBUG: false
// }
// }
// }))
// .pipe(gulp.dest(buildFolder));
// }).catch(ex => {
// console.error(ex);
// });
// });
gulp.task('dist', gulp.series('cleanSrc', () => {
console.time('dist');
return del('./dist').then(() => {
combineTool.config({
debug: false
});
return combineTool.combine();
}).then(() => {
console.timeEnd('dist');
return gulp.src([
'./src/editor.js',
'./src/gallery/**',
'./src/cainiao/**',
'./src/util/**',
'./src/i18n/**',
'./src/service/**',
'./src/element/**',
'./src/editor/**'])
.pipe(concat('editor.js'))
.pipe(uglify({
compress: {
drop_console: true,
drop_debugger: true,
global_defs: {
DEBUG: false
}
},
output: {
ascii_only: true
}
}))
.pipe(gulp.dest('./dist'));
});
}));