-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
59 lines (53 loc) · 1.85 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
const
fs = require('fs'),
path = require('path'),
webpack = require('webpack-stream'),
webpackConfig = require('./webpack.config'),
named = require('vinyl-named'),
gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify-es').default,
rename = require('gulp-rename'),
ts = require('gulp-typescript'),
del = require('del'),
tsProject = ts.createProject('tsconfig.json'),
srcFolder = './src';
function getOutputFolderName() {
const outDir = tsProject.options.outDir.split('/');
return outDir[outDir.length - 1];
}
function getFileOriginalName(filename) {
return filename.substring(0, filename.lastIndexOf('.'))
}
function getFilePureName(dirname) {
const dirs = dirname.split(path.sep);
return dirs[dirs.length - 1];
}
gulp.task('clean', () => {
return del(getOutputFolderName());
});
gulp.task('script', async () => {
return gulp.src(`${srcFolder}/**/page-index.ts`)
.pipe(named((file) => {
return file.path.substring(file.path.indexOf('src') + 4).replace('.ts', '');
}))
.pipe(webpack(webpackConfig))
.pipe(rename((path) => {
if(path.dirname !== '.') {
path.basename = getFilePureName(path.dirname)
}
}))
.pipe(gulp.dest(`./${getOutputFolderName()}`))
.pipe(uglify())
.pipe(rename((path) => {
if(path.dirname !== '.') {
path.basename = `${getFilePureName(path.dirname)}.min`;
}
}))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write(''))
.pipe(gulp.dest(`./${getOutputFolderName()}`))
});
gulp.task('default', gulp.series('clean', gulp.series('script', () => {
gulp.watch(`${srcFolder}/**/*.ts`, gulp.parallel('script'));
})));