forked from xiaolin/react-image-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (82 loc) · 2.44 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
89
90
91
92
const babel = require('gulp-babel');
const browserify = require('browserify');
const concat = require('gulp-concat');
const connect = require('gulp-connect');
const gulp = require('gulp');
const livereload = require('gulp-livereload');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const watchify = require('watchify');
const babelOptions = {
plugins: ['transform-object-assign'],
presets: ['es2015', 'react', 'stage-0'],
};
gulp.task('server', () => {
connect.server({
host: '0.0.0.0',
root: ['example', 'build', 'styles'],
port: 8001,
livereload: true,
});
});
gulp.task('sass', () => {
gulp.src('./styles/scss/image-gallery.scss')
.pipe(sass())
.pipe(rename('image-gallery.css'))
.pipe(gulp.dest('./styles/css/'))
.pipe(livereload());
});
gulp.task('scripts', () => {
watchify(browserify({
entries: './example/app.js',
extensions: ['.jsx'],
debug: true,
}).transform('babelify', babelOptions))
.bundle()
.on('error', (err) => console.error('error is', err))
.pipe(source('example.js'))
.pipe(buffer())
.pipe(gulp.dest('./example/'))
.pipe(livereload());
});
gulp.task('demo-src', () => {
process.env.NODE_ENV = 'production';
browserify({
entries: './example/app.js',
extensions: ['.jsx'],
debug: true,
}).transform('babelify', babelOptions)
.bundle()
.pipe(source('demo.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./demo/'));
gulp.src(['./styles/css/image-gallery.css', './example/app.css'])
.pipe(concat('demo.css'))
.pipe(cleanCSS({ keepSpecialComments: false }))
.pipe(gulp.dest('./demo/'));
});
gulp.task('source-js', () => (
gulp.src('./src/ImageGallery.jsx')
.pipe(concat('image-gallery.js'))
.pipe(babel(babelOptions))
.pipe(gulp.dest('./build'))
));
gulp.task('svg-js', () => (
gulp.src('./src/SVG.jsx')
.pipe(concat('SVG.js'))
.pipe(babel(babelOptions))
.pipe(gulp.dest('./build'))
));
gulp.task('watch', () => {
livereload.listen();
gulp.watch(['styles/**/*.scss'], ['sass']);
gulp.watch(['src/*.jsx', 'src/icons/*.jsx', 'example/app.js'], ['scripts']);
});
gulp.task('dev', ['watch', 'scripts', 'sass', 'server']);
gulp.task('build', ['source-js', 'svg-js', 'sass']);
gulp.task('demo', ['demo-src']);