-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpBase.js
54 lines (44 loc) · 1.77 KB
/
gulpBase.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
var gutil = require('gulp-util'),
less = require('gulp-less'),
path = require('path'),
jshint = require('gulp-jshint'),
react = require('gulp-react'),
webpack = require('webpack'),
shell = require('gulp-shell');
function loadTemplate(template) {
return this.fs.readFileSync(template).toString();
}
module.exports = {
createDefaultTasks: function(gulp, config) {
var rootDir = config.rootDir;
var prodPort = process.env.PORT || 8080;
gulp.task("default", ['less', 'jsx']);
gulp.task("less", doLess);
gulp.task('jsx', function () { doJsx(); });
gulp.task("webpack", doWebpack);
function doLess() {
return gulp.src(path.join(rootDir, 'styles/index.less'))
.pipe(less({paths: [ path.join(rootDir, 'styles') ],
sourceMap:true,
sourceMapBasepath:rootDir,
sourceMapRootpath:'/'}))
.on('error', gutil.log)
.pipe(gulp.dest(path.join(rootDir, '/public/css')));
}
function doWebpack(callback) {
return webpack(config.webpackConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({}));
callback();
});
}
function doJsx() {
//shell.task(['touch ' + path.join(rootDir, '/public/js/') + 'testMain.js']);
return gulp.src(['src/**/*.jsx', 'src/**/*.js'])
//.pipe(debug({verbose: true})) // can enable if you run into issues
.pipe(react({harmony:true}))
.on('error', gutil.log)
.pipe(gulp.dest(path.join(rootDir, '/public/js')));
}
}
};