1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-28 09:20:52 +01:00

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 * 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 => { 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 * 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")) load("assets/images/build/ico"))
/* /*
* Copy and minify vector graphics * 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")) load("assets/images/build/svg"))
/* /*
* Copy images * Copy images
*/ */
gulp.task("assets:images:build", args.clean ? [ gulp.task("assets:images:build", [
"assets:images:clean" "assets:images:build:ico",
] : [], () => { "assets:images:build:svg"
return gulp.start([ ])
"assets:images:build:ico",
"assets:images:build:svg"
])
})
/* /*
* Clean images generated by build * Clean images generated by build
@ -136,29 +143,30 @@ gulp.task("assets:images:clean",
/* /*
* Build application logic * 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")) load("assets/javascripts/build/application"))
/* /*
* Build custom modernizr * Build custom modernizr
*/ */
gulp.task("assets:javascripts:build:modernizr", [ gulp.task("assets:javascripts:build:modernizr", [
"assets:stylesheets:build" "assets:stylesheets:build",
], load("assets/javascripts/build/modernizr")) 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 * Build application logic and modernizr
*/ */
gulp.task("assets:javascripts:build", (args.clean ? [ gulp.task("assets:javascripts:build", [
"assets:javascripts:clean" "assets:javascripts:build:application",
] : []).concat(args.lint ? [ "assets:javascripts:build:modernizr"
"assets:javascripts:lint" ])
] : []), () => {
return gulp.start([
"assets:javascripts:build:application",
"assets:javascripts:build:modernizr"
])
})
/* /*
* Clean JavaScript generated by build * Clean JavaScript generated by build
@ -179,11 +187,10 @@ gulp.task("assets:javascripts:lint",
/* /*
* Build stylesheets from SASS source * Build stylesheets from SASS source
*/ */
gulp.task("assets:stylesheets:build", (args.clean ? [ gulp.task("assets:stylesheets:build", [
"assets:stylesheets:clean" args.clean ? "assets:stylesheets:clean" : null,
] : []).concat(args.lint ? [ args.lint ? "assets:stylesheets:lint" : null
"assets:stylesheets:lint" ].filter(t => t),
] : []),
load("assets/stylesheets/build")) load("assets/stylesheets/build"))
/* /*
@ -227,13 +234,14 @@ gulp.task("assets:clean", [
/* /*
* Minify views * Minify views
*/ */
gulp.task("views:build", (args.revision ? [
"assets:images:build", gulp.task("views:build", [
"assets:stylesheets:build", args.revision ? "assets:images:build" : null,
"assets:javascripts:build" args.revision ? "assets:stylesheets:build" : null,
] : []).concat(args.clean ? [ args.revision ? "assets:javascripts:build" : null,
"views:clean" args.clean ? "views:clean" : null
] : []), load("views/build")) ].filter(t => t),
load("views/build"))
/* /*
* Clean views * Clean views
@ -252,7 +260,8 @@ gulp.task("mkdocs:build", [
"assets:build", "assets:build",
"views:build", "views:build",
"mkdocs:clean" "mkdocs:clean"
], load("mkdocs/build")) ],
load("mkdocs/build"))
/* /*
* Clean documentation build * Clean documentation build
@ -285,10 +294,9 @@ gulp.task("tests:unit:watch",
*/ */
gulp.task("build", [ gulp.task("build", [
"assets:build", "assets:build",
"views:build" "views:build",
].concat(args.mkdocs args.mkdocs ? "mkdocs:build" : null
? "mkdocs:build" ].filter(f => f))
: []))
/* /*
* Clean assets and documentation * Clean assets and documentation

View File

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