forked from vercel/styled-jsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
73 lines (63 loc) · 1.58 KB
/
gulpfile.babel.js
File metadata and controls
73 lines (63 loc) · 1.58 KB
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
// Native
import { join } from 'path'
import { gzipSync } from 'zlib'
// Packages
import gulp from 'gulp'
import babel from 'gulp-babel'
import { transformFile } from 'babel-core'
import size from 'human-size'
import benchmark from 'gulp-benchmark'
gulp.task('transpile', () => {
gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('dist'))
})
gulp.task('runtime-size', async () => {
const files = [
'stylesheet-registry.js',
'server.js',
'style.js',
'lib/stylesheet.js'
]
const result = await Promise.all(
files.map(f => join(__dirname, 'src', f)).map(transform)
)
const code = result.map(({ code }) => code).join('')
console.log('-----------------------------------------------')
console.log('files:', files.join(', '))
console.log('minified:', size(code.length))
console.log('minified and gzipped:', size(gzipSync(code).length))
console.log('-----------------------------------------------')
function transform(file) {
return new Promise((resolve, reject) => {
transformFile(
file,
{
presets: ['babili']
},
(err, data) => {
if (err) {
return reject(err)
}
resolve(data)
}
)
})
}
})
gulp.task('benchmark', () => {
gulp
.src('*.js', {
read: false,
cwd: './benchmark'
})
.pipe(babel())
.pipe(benchmark())
})
gulp.task('watch', () => {
gulp.watch('src/*', ['transpile'])
gulp.watch('src/lib/*', ['transpile'])
gulp.watch('benchmark/*.js', ['benchmark'])
})
gulp.task('default', ['transpile', 'watch'])