Update extendBuild modules API

This commit is contained in:
Ivan Nikulin 2017-08-23 00:10:43 +02:00
parent 416b84ccae
commit 2336b3e6ea
No known key found for this signature in database
GPG Key ID: F800F559F11A1A10
3 changed files with 15 additions and 24 deletions

View File

@ -72,12 +72,20 @@ export function chainFn (base, fn) {
if (!(fn instanceof Function)) {
return
}
return function () {
if (base instanceof Function) {
base.apply(this, arguments)
if (typeof base !== 'function') {
return fn.apply(this, arguments)
}
fn.apply(this, arguments)
let baseResult = base.apply(this, arguments)
// Allow function to mutate the first argument instead of returning the result
if (baseResult === undefined) {
baseResult = arguments[0]
}
let fnResult = fn.call(this, baseResult, ...arguments.slice(1))
// Return mutated argument if no result was returned
if (fnResult === undefined) {
return baseResult
}
return fnResult
}
export function isPureObject (o) {

View File

@ -74,25 +74,7 @@ export default class ModuleContainer extends Tapable {
}
extendRoutes (fn) {
const extendRoutesFromConfig = this.options.router.extendRoutes
this.options.router.extendRoutes = function (routes, resolve) {
/* istanbul ignore if */
if (!(fn instanceof Function)) {
return
}
if (typeof extendRoutesFromConfig !== 'function') {
return fn.call(this, routes, resolve)
}
let extendedRoutes = extendRoutesFromConfig.call(this, routes, resolve)
if (extendedRoutes === undefined) {
extendedRoutes = routes
}
let moduleExtendedRoutes = fn.call(this, extendedRoutes, resolve)
if (moduleExtendedRoutes === undefined) {
return extendedRoutes
}
return moduleExtendedRoutes
}
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
}
requireModule (moduleOpts) {

View File

@ -15,6 +15,7 @@ module.exports = function basicModule (options, resolve) {
// Extend build again
this.extendBuild((config, { isClient, isServer }) => {
// Do nothing!
return config
})
// Extend routes