-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
57 lines (47 loc) · 1.45 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
'use strict';
var gulp = require('gulp');
var rename = require('gulp-rename'); // custom name for build files
var webpack = require('gulp-webpack'); // compiles React modules
var header = require('gulp-header'); // custom comment header on build files
var react = require('gulp-react'); // transpiles jsx -> js
// Set banner for production file
var pkg = require('./package.json');
var banner = ['/*!',
' // <%= pkg.name %> v<%= pkg.version %> | <%= pkg.license %> ',
' // Copyright (c) 2016 <%= pkg.author %>',
' */',
''].join('\n');
// Contacat & compress javascript files for module production
gulp.task('build', function(){
gulp.src(['src/*.{js,jsx}'])
.pipe(react({harmony: true}))
.pipe(rename({
basename: 'react-api',
extname: '.js'
}))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('build'));
});
// Contacat & compress javascript files for testing server
gulp.task('build-examples', function(){
// Move files to public directory for testing
gulp.src(['build/*.{js,jsx}'])
.pipe(gulp.dest('examples/modules/'));
gulp.src(['examples/modules/render.js'])
.pipe(webpack({
watch: false,
module: {
loaders: [
{ test: /\.jsx$/, loader: 'jsx-loader' },
],
},
}))
.pipe(rename({
basename: 'app',
extname: '.bundle.js'
}))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('examples/public/scripts/'));
});
// Set default to build
gulp.task('default', ['build', 'build-examples']);