Speed up build by lazy-loading Gulp

This commit is contained in:
squidfunk 2017-01-27 22:40:09 +01:00
parent 53e1977c65
commit fc900aa4b5
2 changed files with 50 additions and 42 deletions

View File

@ -90,9 +90,16 @@ gulp.src = (...glob) => {
/*
* Helper function to load a task
*
* This function returns a callback that will require the task with the given
* name and execute the function that is returned by this task. It omits the
* need to load all tasks upfront, speeding up the build a gazillion times.
*/
const load = task => {
return require(`./${config.lib}/tasks/${task}`)(gulp, config, args)
return done => {
return require(`./${config.lib}/tasks/${task}`)
.call(gulp, gulp, config, args)(done)
}
}
/* ----------------------------------------------------------------------------
@ -102,26 +109,26 @@ const load = task => {
/*
* Copy favicon
*/
gulp.task("assets:images:build:ico",
gulp.task("assets:images:build:ico", [
args.clean ? "assets:images:clean" : null
].filter(t => t),
load("assets/images/build/ico"))
/*
* Copy and minify vector graphics
*/
gulp.task("assets:images:build:svg",
gulp.task("assets:images:build:svg", [
args.clean ? "assets:images:clean" : null
].filter(t => t),
load("assets/images/build/svg"))
/*
* Copy images
*/
gulp.task("assets:images:build", args.clean ? [
"assets:images:clean"
] : [], () => {
return gulp.start([
"assets:images:build:ico",
"assets:images:build:svg"
])
})
gulp.task("assets:images:build", [
"assets:images:build:ico",
"assets:images:build:svg"
])
/*
* Clean images generated by build
@ -136,29 +143,30 @@ gulp.task("assets:images:clean",
/*
* Build application logic
*/
gulp.task("assets:javascripts:build:application",
gulp.task("assets:javascripts:build:application", [
args.clean ? "assets:javascripts:clean" : null,
args.lint ? "assets:javascripts:lint" : null
].filter(t => t),
load("assets/javascripts/build/application"))
/*
* Build custom modernizr
*/
gulp.task("assets:javascripts:build:modernizr", [
"assets:stylesheets:build"
], load("assets/javascripts/build/modernizr"))
"assets:stylesheets:build",
args.clean ? "assets:javascripts:clean" : null,
args.lint ? "assets:javascripts:lint" : null
].filter(t => t),
load("assets/javascripts/build/modernizr"))
/*
* Build application logic and modernizr
*/
gulp.task("assets:javascripts:build", (args.clean ? [
"assets:javascripts:clean"
] : []).concat(args.lint ? [
"assets:javascripts:lint"
] : []), () => {
return gulp.start([
"assets:javascripts:build:application",
"assets:javascripts:build:modernizr"
])
})
gulp.task("assets:javascripts:build", [
"assets:javascripts:build:application",
"assets:javascripts:build:modernizr"
])
/*
* Clean JavaScript generated by build
@ -179,11 +187,10 @@ gulp.task("assets:javascripts:lint",
/*
* Build stylesheets from SASS source
*/
gulp.task("assets:stylesheets:build", (args.clean ? [
"assets:stylesheets:clean"
] : []).concat(args.lint ? [
"assets:stylesheets:lint"
] : []),
gulp.task("assets:stylesheets:build", [
args.clean ? "assets:stylesheets:clean" : null,
args.lint ? "assets:stylesheets:lint" : null
].filter(t => t),
load("assets/stylesheets/build"))
/*
@ -227,13 +234,14 @@ gulp.task("assets:clean", [
/*
* Minify views
*/
gulp.task("views:build", (args.revision ? [
"assets:images:build",
"assets:stylesheets:build",
"assets:javascripts:build"
] : []).concat(args.clean ? [
"views:clean"
] : []), load("views/build"))
gulp.task("views:build", [
args.revision ? "assets:images:build" : null,
args.revision ? "assets:stylesheets:build" : null,
args.revision ? "assets:javascripts:build" : null,
args.clean ? "views:clean" : null
].filter(t => t),
load("views/build"))
/*
* Clean views
@ -252,7 +260,8 @@ gulp.task("mkdocs:build", [
"assets:build",
"views:build",
"mkdocs:clean"
], load("mkdocs/build"))
],
load("mkdocs/build"))
/*
* Clean documentation build
@ -285,10 +294,9 @@ gulp.task("tests:unit:watch",
*/
gulp.task("build", [
"assets:build",
"views:build"
].concat(args.mkdocs
? "mkdocs:build"
: []))
"views:build",
args.mkdocs ? "mkdocs:build" : null
].filter(f => f))
/*
* Clean assets and documentation

View File

@ -29,7 +29,7 @@ import vinyl from "vinyl-paths"
export default (gulp, config) => {
return () => {
return gulp.src(`${config.views.build}/**/*.html`)
return gulp.src(`${config.views.build}/**/*.{html,py}`)
.pipe(vinyl(clean))
}
}