-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.babel.js
95 lines (81 loc) · 2.87 KB
/
gulpfile.babel.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
'use strict';
import gulp from 'gulp';
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import browserify from "browserify";
import rev from 'gulp-rev';
import cache from 'gulp-cached';
import remember from 'gulp-remember';
import concat from 'gulp-concat';
import gulpif from 'gulp-if';
import source from 'vinyl-source-stream';
import cssnanoe from 'gulp-cssnano';
import runSequence from 'run-sequence';
import gulpWebpack from 'webpack-stream';
import webpack from 'webpack';
import "@babel/polyfill";
const basePaths = {
packages: './node_modules',
dest: './static',
src: './assets'
};
const sassPaths = {
src: [`${basePaths.src}/sass/base.scss`, `${basePaths.src}/sass/webapp.scss`],
dest: `${basePaths.dest}/css/`
};
const scriptPaths = {
src: [`${basePaths.src}/js/base.js`, `${basePaths.src}/js/webapp.js`],
dest: `${basePaths.dest}/js`
};
const webpackConfiguration = require('./assets/webpack.config.js');
const webpackConfigurationProduction = require('./assets/webpack.production.config');
let handleError = function (err) {
console.log(err.toString());
this.emit('end');
};
let enabled = {
rev: 0
};
gulp.task('setproduction', (done) => {
enabled.rev = 1;
done();
});
gulp.task('watch', () => {
gulp.watch(`${basePaths.src}/js/**/**.js`, gulp.series('webpack'));
gulp.watch(`${basePaths.src}/sass/**/**.*`, gulp.series('styles')).on('change', function(evt) {
if (evt.type === 'deleted') {
delete cache.caches.styles[evt.path];
remember.forget('styles', evt.path);
}
if (cache.caches.styles) {
if (cache.caches.styles['/app/assets/sass/webapp.scss']) {
delete cache.caches.styles['/app/assets/sass/webapp.scss'];
}
}
});
});
gulp.task('styles', () => {
return gulp.src(sassPaths.src)
.pipe(sourcemaps.init())
.pipe(cache('styles'))
.pipe(sass.sync().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulpif(enabled.rev, cssnanoe()))
.pipe(remember('styles'))
.pipe(concat('webapp' + ((enabled.rev) ? '.min' : '') + '.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(sassPaths.dest));
});
gulp.task('webpack', () => {
return gulp.src(scriptPaths.src)
.pipe(gulpWebpack((enabled.rev) ? webpackConfigurationProduction : webpackConfiguration, webpack).on('error', function() {this.emit('end');}))
.pipe(concat('webapp' + ((enabled.rev) ? '.min' : '') + '.js'))
.pipe(gulp.dest(scriptPaths.dest))
.pipe(gulpif(enabled.rev, rev.manifest(scriptPaths.dest + '/manifest.json', {
base: scriptPaths.dest,
merge: true,
})))
.pipe(gulp.dest(scriptPaths.dest));
});
gulp.task('deploy', gulp.series('setproduction', 'styles', 'webpack'));