-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove deprecated warnings from gulp
- Loading branch information
Showing
5 changed files
with
77 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,68 @@ | ||
// js.js | ||
const { src, dest, parallel } = require('gulp'); | ||
const rename = require('gulp-rename'); | ||
const minify = require('gulp-babel-minify'); | ||
const sass = require('sass'); | ||
const through2 = require('through2'); | ||
const config = require('../config'); | ||
|
||
// Process JavaScript files | ||
function processFiles() { | ||
return src(['src/assets/js/*.js']) | ||
.pipe( | ||
rename(function (path) { | ||
// Returns a completely new object, make sure you return all keys needed! | ||
return { | ||
dirname: path.dirname, | ||
basename: path.basename, | ||
extname: '.min.js', | ||
}; | ||
rename((path) => { | ||
path.extname = '.min.js'; | ||
}) | ||
) | ||
.pipe(minify(config.minify)) | ||
.pipe(dest(config.dirs.dist + '/js')); | ||
} | ||
|
||
// Process vendor JavaScript files | ||
function copyVendorFiles() { | ||
return src(['src/assets/js/vendor/*.js']) | ||
.pipe( | ||
rename(function (path) { | ||
// We don't need to rename if .min is already in filename | ||
if (path.basename.endsWith('.min')) { | ||
return path; | ||
rename((path) => { | ||
if (!path.basename.endsWith('.min')) { | ||
path.extname = '.min.js'; | ||
} | ||
|
||
return { | ||
dirname: path.dirname, | ||
basename: path.basename, | ||
extname: '.min.js', | ||
}; | ||
}) | ||
) | ||
.pipe(minify(config.minify)) | ||
.pipe(dest(config.dirs.dist + '/js')); | ||
} | ||
|
||
/** | ||
* Build standalone js files. | ||
* | ||
* @returns | ||
*/ | ||
function miscJs() { | ||
let process = processFiles(); | ||
|
||
let copy = copyVendorFiles(); | ||
// Process SCSS files with modern Sass API | ||
function styles() { | ||
return src('src/assets/scss/**/*.scss') | ||
.pipe( | ||
through2.obj(function (file, _, callback) { | ||
if (file.isBuffer()) { | ||
try { | ||
// Using the modern Sass API | ||
const result = sass.compile(file.path, { | ||
style: 'compressed', | ||
}); | ||
file.contents = Buffer.from(result.css); | ||
file.extname = '.css'; | ||
this.push(file); | ||
} catch (err) { | ||
this.emit('error', err); | ||
} | ||
} | ||
callback(); | ||
}) | ||
) | ||
.pipe(dest(config.dirs.dist + '/css')); | ||
} | ||
|
||
return copy; | ||
// Parallel tasks for JavaScript | ||
function miscJs() { | ||
return parallel(processFiles, copyVendorFiles)(); | ||
} | ||
|
||
exports.miscJs = miscJs; | ||
|
||
exports.styles = styles; | ||
exports.buildJs = parallel(miscJs); | ||
exports.js = parallel(miscJs); | ||
exports.default = parallel(styles, miscJs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters