forked from xdan/jodit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
105 lines (85 loc) · 2.12 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
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
const gulp = require('gulp');
const path = require('path');
const webpack = require('webpack-stream');
const less = require('gulp-less');
const imagemin = require('gulp-imagemin');
const rootPath = path.resolve(process.cwd()) + path.sep;
const make = require(path.resolve(rootPath, './make.js'));
const entries = require('./src/utils/create-entries');
const mergeStream = require('merge-stream');
const files = entries.resolve(make.paths);
function buildOneFile(file, list) {
console.log('Build file: ' + file);
file = path.resolve(file);
const full = path.dirname(file).replace(rootPath, '');
const ext = path.extname(file).toLowerCase();
const filename = path.basename(file, ext);
let pipe = gulp.src(file).on('error', error => {
console.warn(error);
});
switch (ext) {
case '.ts': {
const opt = require(path.resolve(rootPath, './webpack.config.js'))([], {
mode: 'production',
isTest: false,
uglify: true,
es: 'es5'
}, process.cwd(), true);
pipe = pipe.pipe(
webpack({
...opt,
entry: file,
output: {
filename: filename + '.js'
},
})
);
break;
}
case '.less':
console.log(file, ext);
pipe = pipe.pipe(less());
break;
case '.ico':
case '.svg':
case '.png':
case '.jpg':
case '.jpeg':
pipe = pipe.pipe(imagemin());
break;
default:
break;
}
return pipe.pipe(gulp.dest('build/' + full));
}
function build() {
if (!files.length) {
return gulp.src('.');
}
const list = [...files];
let pipes = [];
while (list.length) {
const file = list.shift();
file && pipes.push(buildOneFile(file, list));
}
return mergeStream.apply(null, pipes);
}
exports.watch = function watch() {
if (!files.length) {
return gulp.src('.');
}
files.forEach(file => {
gulp.watch(
file,
{ ignoreInitial: false },
buildOneFile.bind(null, file)
);
});
};
exports.default = () => gulp.parallel('watch');
exports.build = build;