-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
149 lines (133 loc) · 3.78 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const gulp = require('gulp');
const webpack = require('webpack');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const runSequence = require('run-sequence');
const gutil = require('gulp-util');
const merge = require('merge-stream');
const nodemon = require('gulp-nodemon');
const livereload = require('gulp-livereload');
// Load Environment constiables
require('dotenv').config();
const webpackConfig = process.env.NODE_ENV === 'development'
? require('./webpack.config.js')
: require('./webpack.config.prod.js');
const jsPaths = [
'static/js/components/*.js'
];
const sassPaths = [
'static/scss/*.scss',
'./node_modules/bootstrap/dist/css/bootstrap.min.css'
];
const filesToCopy = [
{
src: './node_modules/react/dist/react.min.js',
dest: './static/build'
},
{
src: './node_modules/react-dom/dist/react-dom.min.js',
dest: './static/build'
},
{
src: './node_modules/react-bootstrap/dist/react-bootstrap.min.js',
dest: './static/build'
},
{
src: './images/favicon.ico',
dest: './static/build'
},
{
src: './icomoon/symbol-defs.svg',
dest: './static/build'
}
];
gulp.task('copy:react:files', () => {
const streams = [];
filesToCopy.forEach(file => {
streams.push(gulp.src(file.src).pipe(gulp.dest(file.dest)));
});
return merge.apply(this, streams);
});
gulp.task('uglify:js', () => {
return gulp.src(jsPaths)
.pipe(uglify())
.pipe(gulp.dest('static/build'));
});
gulp.task('build:js', (callback) => {
webpack(Object.create(webpackConfig), (err, stats) => {
if (err) {
throw new gutil.PluginError('build:js', err);
}
gutil.log('[build:js]', stats.toString({colors: true, chunks: false}));
callback();
});
});
gulp.task('build:sass', () => {
return gulp.src(sassPaths[0])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed',
includePaths: ['node_modules']
}))
.pipe(autoprefixer({cascade: false}))
.pipe(concat('software-testing.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./static/build'))
.pipe(livereload());
});
gulp.task('build:vendor:sass', () => {
return gulp.src([...sassPaths.slice(1)])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed',
includePaths: ['node_modules']
}))
.pipe(autoprefixer({cascade: false}))
.pipe(concat('vendor.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./static/build'));
});
gulp.task('watch:js', () => {
let config = Object.create(webpackConfig);
config.watch = true;
webpack(config, (err, stats) => {
if (err) {
throw new gutil.PluginError('watch:js', err);
}
gutil.log('[watch:js]', stats.toString({colors: true, chunks: false}));
});
gulp.watch('static/js/components/*.js', ['uglify:js', 'build:js']);
});
gulp.task('watch:sass', () => {
gulp.watch('static/scss/*.scss', ['build:sass']);
});
gulp.task('start', () => {
nodemon({
script: './bin/www',
ignore: ['static/*'],
env: { 'PORT': '3000' }
});
});
gulp.task('debug', () => {
nodemon({
exec: 'node-inspector & node --inspect',
ext: 'js',
ignore: ['static/*'],
script: './bin/www',
verbose: true
});
});
gulp.task('build', (cb) => {
runSequence('copy:react:files', 'uglify:js', 'build:js', 'build:sass', 'build:vendor:sass', cb);
});
gulp.task('dev', (cb) => {
livereload.listen();
runSequence('copy:react:files', 'uglify:js', 'build:sass', 'build:vendor:sass', ['watch:js', 'watch:sass'], 'start', cb);
});
gulp.task('dev:debug', (cb) => {
livereload.listen();
runSequence('copy:react:files', 'uglify:js', 'build:sass', 'build:vendor:sass', ['watch:js', 'watch:sass'], 'debug', cb);
});