-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgulpfile.mjs
80 lines (70 loc) · 1.92 KB
/
gulpfile.mjs
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
import gulp from 'gulp';
import gulpTypescript from 'gulp-typescript';
import gulpSass from 'gulp-sass';
import gulpFilter from 'gulp-filter';
import merge from 'merge2';
import * as sassCompiler from 'sass';
import tsconfig from './tsconfig.json' assert { type: 'json' };
import tsconfigES5 from './tsconfig.es5.json' assert { type: 'json' };
gulpSass.compiler = sassCompiler;
// 文件目录地址
const tsSrc = 'src/**/*.{ts,tsx}';
const dTsSrc = 'src/**/*.d.ts';
const sassSrc = 'src/style/**/*.sass';
const libPath = 'lib';
const esPath = 'es';
const stylePath = 'style';
const typescriptConfig = {
allowSyntheticDefaultImports: true,
rootDir: '.'
};
/* ----- 生产环境编译 ----- */
/* lib */
function proLibProject() {
const result = gulp.src(tsSrc)
.pipe(gulpTypescript({
...tsconfigES5.compilerOptions,
...typescriptConfig
}));
return merge([
result.js.pipe(gulp.dest(libPath)),
result.dts
// 不输出warning.d.ts,因为是空文件
.pipe(gulpFilter((file) => !/warning\.d\.ts/.test(file.path), {
restore: false
}))
.pipe(gulp.dest(libPath))
]);
}
/* es */
function proEsProject() {
const result = gulp.src(tsSrc)
.pipe(gulpTypescript({
...tsconfig.compilerOptions,
...typescriptConfig
}));
return merge([
result.js.pipe(gulp.dest(esPath)),
result.dts
// 不输出warning.d.ts,因为是空文件
.pipe(gulpFilter((file) => !/warning\.d\.ts/.test(file.path), {
restore: false
}))
.pipe(gulp.dest(esPath))
]);
}
/* 拷贝d.ts */
function copy() {
return gulp.src(dTsSrc)
.pipe(gulp.dest(libPath))
.pipe(gulp.dest(esPath));
}
/* sass */
function proSassProject() {
return gulp.src(sassSrc)
.pipe(gulpSass({
outputStyle: 'compressed'
}).on('error', gulpSass.logError))
.pipe(gulp.dest(stylePath));
}
export default gulp.parallel(proLibProject, proEsProject, proSassProject, copy);