-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
52 lines (42 loc) · 1.53 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
/* eslint-env node */
const path = require('path');
const {task, src, dest, series, parallel} = require('gulp');
const sass = require('gulp-dart-sass');
const replace = require('gulp-replace');
const ts = require('gulp-typescript');
const rimraf = require('rimraf');
const BUILD_DIR = path.resolve('build');
task('clean', (done) => {
rimraf.sync(BUILD_DIR);
done();
});
function compileTs(modules = false) {
const tsProject = ts.createProject('tsconfig.json', {
declaration: true,
...(modules ? undefined : {verbatimModuleSyntax: false}),
module: modules ? 'esnext' : 'commonjs',
});
return src(['src/**/*.{ts,tsx}', '!src/**/__stories__/**/*.{ts,tsx}'])
.pipe(replace(/import '.+\.scss';/g, (match) => match.replace('.scss', '.css')))
.pipe(tsProject())
.pipe(dest(path.resolve(BUILD_DIR, modules ? 'esm' : 'cjs')));
}
task('ts-compile-esm', () => {
return compileTs(true);
});
task('ts-compile-cjs', () => {
return compileTs();
});
task('i18n', () => {
return src('src/**/i18n/*.json')
.pipe(dest(path.resolve(BUILD_DIR, 'esm')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs')));
});
task('styles', () => {
return src(['src/**/*.scss', '!src/**/__stories__/**/*.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(dest(path.resolve(BUILD_DIR, 'esm')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs')));
});
task('build', series(['clean', parallel(['ts-compile-cjs', 'ts-compile-esm', 'i18n']), 'styles']));
task('default', series(['build']));