-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (66 loc) · 2.02 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
const gulp = require('gulp')
const babel = require('gulp-babel')
const path = require('path')
const through2 = require('through2')
const merge2 = require('merge2')
const runSequence = require('run-sequence')
const transformSass = require('./build/transformSass')
const rimraf = require('rimraf')
const cwd = process.cwd()
const libDir = path.join(cwd, 'lib')
const esDir = path.join(cwd, 'es')
const compile = (modules) => {
rimraf.sync(modules !== false ? libDir : esDir)
const sass = gulp
.src(['src/**/*.scss', '!src/**/_*.scss'])
.pipe(
through2.obj(function (file, encoding, next) {
// this.push(file.clone())
if (file.path.match(/\/style\/.*\.scss$/)) {
transformSass(file.path)
.then((css) => {
file.contents = Buffer.from(css)
file.path = file.path.replace(/\.scss$/, '.css')
this.push(file)
next()
})
.catch((e) => {
console.error(e)
})
} else {
next()
}
})
)
.pipe(gulp.dest(modules === false ? esDir : libDir))
const assets = gulp
.src(['src/**/*.@(png|svg|eot|ttf|woff|woff2|otf)'])
.pipe(gulp.dest(modules === false ? esDir : libDir))
const js = gulp
.src(['src/**/*.js', 'src/**/*.jsx'])
.pipe(
babel({
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [['transform-remove-console', { exclude: ['error', 'warn'] }]]
})
)
.pipe(
through2.obj(function (file, encoding, next) {
if (file.path.match(/\/.*\.js$/)) {
const cssContent = file.contents.toString().replace(/\.scss/g, '.css')
file.contents = Buffer.from(cssContent)
this.push(file)
next()
} else {
this.push(file)
next()
}
})
)
.pipe(gulp.dest(modules === false ? esDir : libDir))
return merge2([sass, assets, js])
}
gulp.task('compile', () => compile(false))
gulp.task('default', () => {
runSequence('compile')
})