-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
65 lines (57 loc) · 1.81 KB
/
gulpfile.js
File metadata and controls
65 lines (57 loc) · 1.81 KB
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
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const gulpif = require('gulp-if');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const stripComments = require('gulp-strip-comments');
const isProduction = process.env.NODE_ENV === 'production';
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
function addJSFolder(name, src, prependSrc = []) {
if (typeof prependSrc === 'string') prependSrc = [prependSrc];
return gulp
.src(src)
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(babel({ presets: ['env'] }))
.pipe(concat(`${name}.js`))
.pipe(stripComments())
.pipe(gulpif(isProduction, uglify()))
.pipe(gulpif(!isProduction, sourcemaps.write()))
.pipe(gulp.dest('./public/js'))
}
gulp.task('vendor', () =>
addJSFolder('vendor', [
'./app/assets/js/vendor/jquery-3.2.1.min.js',
'./app/assets/js/vendor/bootstrap.min.js',
], [])
);
gulp.task('app', () =>
addJSFolder('app', './app/assets/js/*.js', [])
);
gulp.task('styles', () =>
gulp.src([
'./app/assets/scss/*.scss',
])
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(
sass({
outputStyle: isProduction ? 'compressed' : 'expanded',
})
.on('error', sass.logError)
)
.pipe(gulpif(!isProduction, sourcemaps.write({ includeContent: false })))
.pipe(gulpif(!isProduction, sourcemaps.init({ loadMaps: true })))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ios 6', 'android 4'))
.pipe(gulpif(!isProduction, sourcemaps.write()))
.pipe(gulp.dest('./public/css'))
);
gulp.task('build', [
'vendor',
'app',
'styles',
]);
gulp.task('watch', () => {
gulp.watch(`./app/assets/scss/*.scss`, ['styles']);
gulp.watch(`./app/assets/js/*.js`, ['vendor', 'app']);
});