-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
executable file
·92 lines (74 loc) · 2.31 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
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
var package = require('./package.json');
var shell = require('gulp-shell');
// The task that handles both development and deployment
var runBrowserifyTask = function (options) {
// This bundle is for our application
var bundler = browserify({
debug: options.debug, // Need that sourcemapping
standalone: 'flux-react',
// These options are just for Watchify
cache: {}, packageCache: {}, fullPaths: options.watch
})
.require(require.resolve('./src/main.js'), { entry: true })
.external('react');
// The actual rebundle process
var rebundle = function () {
var start = Date.now();
bundler.bundle()
.on('error', gutil.log)
.pipe(source(options.name))
.pipe(gulpif(options.uglify, streamify(uglify())))
.pipe(gulp.dest(options.dest))
.pipe(notify(function () {
// Fix for requirejs
var fs = require('fs');
var file = fs.readFileSync(options.dest + '/' + options.name).toString();
file = file.replace('define([],e)', 'define(["react"],e)');
fs.writeFileSync(options.dest + '/' + options.name, file);
console.log('Built in ' + (Date.now() - start) + 'ms');
}));
};
// Fire up Watchify when developing
if (options.watch) {
bundler = watchify(bundler);
bundler.on('update', rebundle);
}
return rebundle();
};
gulp.task('default', function () {
runBrowserifyTask({
watch: true,
dest: './build',
uglify: false,
debug: true,
name: 'flux-react.js'
});
});
gulp.task('deploy', function () {
runBrowserifyTask({
watch: false,
dest: './releases/' + package.version,
uglify: true,
debug: false,
name: 'flux-react-' + package.version + '.min.js'
});
runBrowserifyTask({
watch: false,
dest: './releases/' + package.version,
uglify: false,
debug: false,
name: 'flux-react-' + package.version + '.js'
});
});
gulp.task('test', shell.task([
'./node_modules/.bin/jasmine-node ./specs --autotest --watch ./src --color'
]));