forked from idmontie/gulp-react-scss-hot-loading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
83 lines (68 loc) · 1.97 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
require('babel-core/register');
var gulp = require('gulp'),
touch = require('touch'),
sass = require('gulp-sass'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
webpackConfig = require('./webpack.config.js'),
eslint = require('gulp-eslint'),
mocha = require('gulp-mocha');
var devServer = {};
gulp.task('css', function () {
return gulp.src('./src/styles/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/styles'));
});
gulp.task('copy-assets', function () {
gulp.src('src/index.html')
.pipe(gulp.dest('./dist'));
});
gulp.task('webpack-prod', function(callback) {
process.env.NODE_ENV = 'production';
webpack(webpackConfig('PROD'), function(err, stats) {
callback();
});
});
gulp.task('webpack-dev-server', ['css'], function(callback) {
touch.sync('./dist/styles/main.css', {time : new Date(0) });
devServer = new WebpackDevServer(webpack(webpackConfig('DEBUG')), {
contentBase: './dist',
hot: true,
watchOptions: {
aggregateTimeout: 100,
poll: 300
},
publicPath: '/js/',
noInfo: true,
historyApiFallback: true
});
devServer.listen(3000, "0.0.0.0", function (err) {
if (err) {
console.log(err);
throw err;
}
console.log( '[webpack-dev-server]', 'http://localhost:3000' );
if (callback)
callback();
});
});
gulp.task('watch', ['css', 'copy-assets', 'webpack-dev-server'], function () {
gulp.watch(['src/styles/**'], ['css']);
gulp.watch(['assets/**', 'src/index.html'], ['copy-assets']);
});
gulp.task('lint', function() {
return gulp.src(['src/js/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('test', function () {
gulp.src([
'tests/**/*.js',
'tests/**/*.jsx'
]).pipe(mocha());
});
gulp.task('build', ['css', 'copy-assets', 'webpack-prod']);
gulp.task('default', ['lint', 'test'], function () {
gulp.start('build');
});