-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
82 lines (66 loc) · 1.88 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
var gulp = require( 'gulp' );
var path = require( 'path' );
var gutil = require( 'gulp-util' );
var webpack = require( 'webpack' );
var sass = require( 'gulp-sass' );
var autoprefixer = require( 'gulp-autoprefixer' );
var sourcemaps = require( 'gulp-sourcemaps' );
function onBuild( done ) {
return function( err, stats ) {
if ( err ) {
throw new gutil.PluginError( 'webpack', err );
}
gutil.log( 'Building JS…', stats.toString( {
colors: true
} ), "\nJS finished at", Date.now() );
if ( done ) {
done();
}
};
}
function getWebpackConfig() {
// clone and extend webpackConfig
var config = Object.create( require( './webpack.config.js' ) );
config.devtool = "sourcemap";
config.debug = true;
return config;
}
function doSass() {
if ( arguments.length ) {
console.log( 'Sass file ' + arguments[0].path + ' changed.' );
}
console.log( 'Building CSS bundle' );
gulp.src( './css/scss/components.scss' )
.pipe( sass().on( 'error', sass.logError ) )
.pipe( autoprefixer() )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( './css' ) )
.on( 'end', function() {
console.log( 'CSS finished.' );
} );
}
gulp.task( 'sass:build', function() {
doSass();
} );
gulp.task( 'sass:watch', function() {
doSass();
gulp.watch( [ './**/*.scss' ], doSass );
} );
gulp.task( 'react:build', function( done ) {
process.env.NODE_ENV = 'production';
var config = getWebpackConfig();
config.plugins = config.plugins.concat(
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
config.devtool = 'source-map';
config.debug = false;
webpack( config ).run( onBuild( done ) );
} );
gulp.task( 'react:watch', function() {
process.env.NODE_ENV = "production";
var config = getWebpackConfig();
webpack( config ).watch( 100, onBuild() );
} );
gulp.task( 'default', ['react:build', 'sass:build'] );
gulp.task( 'watch', ['react:watch', 'sass:watch'] );