-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
92 lines (77 loc) · 2.38 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
const gulp = require('gulp');
const del = require('del');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const argv = require('yargs').argv;
const iff = require('gulp-if');
const size = require('gulp-size');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
sass.compiler = require('node-sass');
const devBuild = argv.production || argv.prod;
const dir = {
src: 'assets/src/',
build: 'assets/dist/'
};
const clean = () => {
return del([dir.build]);
};
exports.clean = clean;
const cssConfig = {
src: dir.src + 'scss/main.scss',
build: dir.build + 'css',
sassOpts: {
sourceMap: devBuild,
outputStyle: 'nested',
precision: 3,
logErrorsToConsole: true,
outFile: dir.build + 'css'
},
postCSS: [
require('autoprefixer')()
]
};
if (!devBuild) {
cssConfig.postCSS.push(require('cssnano'));
}
const css = () =>
gulp.src(cssConfig.src)
.pipe(iff(cssConfig.sassOpts.sourceMap, sourcemaps.init()))
.pipe(sass(cssConfig.sassOpts).on('error', sass.logError))
.pipe(postcss(cssConfig.postCSS))
.pipe(iff(cssConfig.sassOpts.sourceMap, sourcemaps.write('./')))
.pipe(size({ showFiles: true }))
.pipe(rename({suffix: '.min' }))
.pipe(gulp.dest(cssConfig.build));
exports.css = css;
const jsConfig = {
srcRoot: dir.src + 'js/',
build: dir.build + 'js/'
};
const jsBundles = {
primary: {
sources: [
'globals/jquery-3.3.1.slim.min.js', 'globals/jquery-migrate-3.0.1.js',
'globals/plugins.js', 'globals/bootstrap/*.js', 'globals/functions.js'
].map(src => jsConfig.srcRoot + src),
dest: 'all.js'
}
};
const js = ({ sources, dest }) => {
return () => gulp.src(sources)
.pipe(iff(devBuild, sourcemaps.init()))
.pipe(concat(dest))
.pipe(babel())
.pipe(gulp.dest(jsConfig.build))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(iff(devBuild, sourcemaps.write('./')))
.pipe(gulp.dest(jsConfig.build));
}
const jsPrimary = js(jsBundles.primary);
const buildJs = gulp.parallel(jsPrimary, jsRegipedia);
const buildAll = gulp.parallel(buildJs, css);
gulp.task('default', buildAll);