This repository was archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
86 lines (73 loc) · 2.83 KB
/
gulpfile.js
File metadata and controls
86 lines (73 loc) · 2.83 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/// ShipShape -> gulpfile.js
/// Handles compilation of assets and watching files for recompilation.
// Determine whether or not we are running in a development environment.
let dev = process.env.NODE_ENV != 'production';
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const noop = require('gulp-noop');
const sourcemaps = dev ? require('gulp-sourcemaps') : null;
const uglify = require('gulp-uglify');
sass.compiler = require("node-sass");
// Build CSS files from SCSS files using the 'node-sass-import-once' importer.
gulp.task('build-css', () =>
gulp.src('app/res/scss/**/*.scss')
// If we are in development, initialize the sourcemaps.
.pipe(dev ? sourcemaps.init() : noop())
// Compile the SCSS.
.pipe(sass({
// We don't want to import files more than once.
importer : require('node-sass-import-once'),
importOnce : {
index : false,
css : true,
bower : false
},
// We are using SCSS and not SASS.
indentedSyntax : false,
// Generate minified CSS in production.
outputStyle : dev ? 'nested' : 'compressed'
}).on('error', sass.logError))
// Add vendor prefixes when necessary.
.pipe(autoprefixer({
// Don't use "visual cascade" when in production.
cascade: dev ? true : false
}))
// Concatenate all CSS files into one file.
.pipe(concat('index.css'))
// Write the finished sourcemaps if we are in development.
.pipe(dev ? sourcemaps.write('./') : noop())
// Output the compiled CSS files.
.pipe(gulp.dest('res/'))
);
// Transpile JS files using Babel.
gulp.task('build-js', () =>
gulp.src('app/res/js/**/*.js')
// If we are in development, initialize the sourcemaps.
.pipe(dev ? sourcemaps.init() : noop())
// Transpile the JS using the 'env' preset.
.pipe(babel({
presets : [ 'env' ]
}))
// Concatenate all of the resulting JS files into one file.
.pipe(concat('index.js'))
// Minify the CSS if we're in production.
.pipe(dev ? noop() : uglify().on('error', sass.logError))
// Write the sourcemaps if we are in development.
.pipe(dev ? sourcemaps.write('./') : noop())
// Output the compiled JS files.
.pipe(gulp.dest('res/'))
);
// Build both CSS and JS in parallel.
gulp.task('build', gulp.parallel('build-css', 'build-js'));
// Watch resource files and compile them if changed.
gulp.task('watch', () => {
// If the SCSS changes, compile it.
gulp.watch('app/res/scss/**/*.scss', gulp.task('build-css'));
// If the JS changes, compile it.
gulp.watch('app/res/js/**/*.js', gulp.task('build-js'));
});
// Build all files and then start watching files (if in development).
gulp.task('default', gulp.series('build', dev ? 'watch' : (callback) => { callback(); }));