-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
121 lines (106 loc) · 3.33 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
// requirements
const gulp = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const rename = require('gulp-rename')
const webpack = require('webpack')
const sourcemaps = require('gulp-sourcemaps')
const resolve = require('path').resolve
const webpackConfig = require('./webpack.config.js')
// define paths
const dest = 'build'
const assetPath = 'assets'
const gensCss = [
`${assetPath}/css/gens.scss`
]
// run webpack
function runWebpack (config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
if (stats.hasErrors()) {
return reject(new Error(stats.compilation.errors.join('\n')))
}
resolve()
})
})
}
// PRODUCTION tasks
gulp.task('build-js', function () {
return runWebpack(webpackConfig)
})
gulp.task('build-gens-css', function () {
return gulp.src(gensCss)
.pipe(rename('gens.min.css'))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(`${dest}/css`))
})
gulp.task('build-home-css', function () {
return gulp.src(`${assetPath}/css/home.scss`)
.pipe(rename('home.min.css'))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(`${dest}/css`))
})
gulp.task('build-about-css', function () {
return gulp.src(`${assetPath}/css/about.scss`)
.pipe(rename('about.min.css'))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(`${dest}/css`))
})
gulp.task('build-error-css', function () {
return gulp.src(`${assetPath}/css/error.scss`)
.pipe(rename('error.min.css'))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(`${dest}/css`))
})
gulp.task('build', gulp.parallel('build-js', 'build-gens-css',
'build-home-css', 'build-about-css', 'build-error-css'))
// DEVELOPMENT tasks
//
const devGlobalAssets = 'gens/static'
const devGensAssets = 'gens/blueprints/gens/static'
const devAboutAssets = 'gens/blueprints/home/static'
gulp.task('build-js-dev', () => {
webpackConfig.mode = 'development'
webpackConfig.output.path = resolve('./gens/blueprints/gens/static/')
return runWebpack(webpackConfig)
})
gulp.task('build-gens-css-dev', () => {
return gulp.src(gensCss)
.pipe(rename('gens.min.css'))
.pipe(sass())
.pipe(gulp.dest(devGensAssets))
})
gulp.task('build-about-css-dev', () => {
return gulp.src(`${assetPath}/css/about.scss`)
.pipe(rename('about.min.css'))
.pipe(sass())
.pipe(gulp.dest(devAboutAssets))
})
gulp.task('build-home-css-dev', () => {
return gulp.src(`${assetPath}/css/home.scss`)
.pipe(rename('home.min.css'))
.pipe(sass())
.pipe(gulp.dest(devAboutAssets))
})
gulp.task('build-error-css-dev', () => {
return gulp.src(`${assetPath}/css/error.scss`)
.pipe(rename('error.min.css'))
.pipe(sass())
.pipe(gulp.dest(`${devGlobalAssets}/css`))
})
gulp.task('watch', () => {
gulp.watch(`${assetPath}/css/*.scss`, gulp.parallel('build-gens-css-dev', 'build-home-css-dev',
'build-about-css-dev', 'build-error-css-dev'))
gulp.watch(`${assetPath}/js/*.js`, gulp.parallel('build-js-dev'))
gulp.watch(`${assetPath}/js/*/*.js`, gulp.parallel('build-js-dev'))
})