-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathgulpfile.js
88 lines (79 loc) · 2.41 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
/* eslint-disable @typescript-eslint/no-var-requires */
const del = require('del');
const babel = require('gulp-babel');
const less = require('gulp-less');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const insert = require('gulp-insert');
const gulp = require('gulp');
const babelrc = require('./babel.config.js');
const STYLE_SOURCE_DIR = './src/less';
const STYLE_DIST_DIR = './dist/css';
const TS_SOURCE_DIR = ['./src/**/*.tsx', './src/**/*.ts', '!./src/**/*.d.ts'];
const ESM_DIR = './es';
const CJS_DIR = './lib';
const DIST_DIR = './dist';
function buildLess() {
return gulp
.src(`${STYLE_SOURCE_DIR}/index.less`)
.pipe(sourcemaps.init())
.pipe(less({ javascriptEnabled: true }))
.pipe(postcss([require('autoprefixer')]))
.pipe(sourcemaps.write('./'))
.pipe(rename('rsuite-table.css'))
.pipe(gulp.dest(`${STYLE_DIST_DIR}`));
}
function buildCSS() {
return gulp
.src(`${STYLE_DIST_DIR}/rsuite-table.css`)
.pipe(sourcemaps.init())
.pipe(postcss())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${STYLE_DIST_DIR}`));
}
function buildLib() {
return (
gulp
.src(TS_SOURCE_DIR)
.pipe(babel(babelrc()))
// adds the 'use-client' directive to /lib exported from rsuite-talbe
.pipe(insert.prepend(`'use client';\n`))
.pipe(gulp.dest(CJS_DIR))
);
}
function buildEsm() {
return gulp
.src(TS_SOURCE_DIR)
.pipe(
babel(
babelrc(null, {
NODE_ENV: 'esm'
})
)
) // adds the 'use-client' directive to /es exported from rsuite-talbe
.pipe(insert.prepend(`'use client';\n`))
.pipe(gulp.dest(ESM_DIR));
}
function copyTypescriptDeclarationFiles() {
return gulp.src('./src/**/*.d.ts').pipe(gulp.dest(CJS_DIR)).pipe(gulp.dest(ESM_DIR));
}
function copyLessFiles() {
return gulp
.src(['./src/**/*.less', './src/**/fonts/**/*'])
.pipe(gulp.dest(CJS_DIR))
.pipe(gulp.dest(ESM_DIR));
}
function copyFontFiles() {
return gulp.src(`${STYLE_SOURCE_DIR}/fonts/**/*`).pipe(gulp.dest(`${STYLE_DIST_DIR}/fonts`));
}
function clean(done) {
del.sync([CJS_DIR, ESM_DIR, DIST_DIR], { force: true });
done();
}
exports.build = gulp.series(
clean,
gulp.parallel(buildLib, buildEsm, gulp.series(buildLess, buildCSS)),
gulp.parallel(copyTypescriptDeclarationFiles, copyLessFiles, copyFontFiles)
);