-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
64 lines (56 loc) · 1.81 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import rename from 'gulp-rename';
import del from 'del';
import sass from 'gulp-sass';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import es from 'event-stream';
import concat from 'gulp-concat';
import glob from 'glob';
const paths = {
sass: 'src/public/sass/*.scss',
js: 'src/ui/client/**.js',
libs: [
'./node_modules/react/dist/react.js',
'./node_modules/react-dom/dist/react-dom.js',
],
jsWatch: 'src/ui/*.jsx',
images: 'src/public/images/*.*',
dist: 'dist/',
};
gulp.task('default', ['build', 'watch']);
gulp.task('build', ['build:sass', 'build:images', 'build:browserify', 'build:libs']);
gulp.task('build:browserify', (done) => {
glob(paths.js, (err, reactJsFiles) => {
if (err) { return done(err); }
const reactFiles = reactJsFiles.map((reactFile) =>
browserify({ entries: reactFile, extensions: ['.js', '.jsx'], debug: true })
.transform(babelify.configure({
presets: ['es2015', 'react'],
plugins: ['syntax-class-properties', 'transform-class-properties'],
}))
.bundle()
.pipe(source(reactFile))
.pipe(rename({ dirname: '' }))
.pipe(gulp.dest(`${paths.dist}/js/`)));
es.merge(reactFiles).on('end', done);
});
});
gulp.task('build:libs', () => {
gulp.src(paths.libs)
.pipe(concat('libs.js'))
.pipe(gulp.dest(`${paths.dist}/js/`));
});
gulp.task('build:sass', () => {
return gulp.src(paths.sass)
.pipe(
sass({
errLogToConsole: true,
})
)
.pipe(gulp.dest(`${paths.dist}css`));
});
gulp.task('clean', () => del(['dest']));
gulp.task('build:images', () => gulp.src([paths.images]).pipe(gulp.dest(`${paths.dist}images`)));
gulp.task('watch', () => gulp.watch([paths.sass, paths.jsWatch], ['build']));