mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
Update extendBuild modules API
This commit is contained in:
parent
416b84ccae
commit
2336b3e6ea
@ -72,12 +72,20 @@ export function chainFn (base, fn) {
|
||||
if (!(fn instanceof Function)) {
|
||||
return
|
||||
}
|
||||
return function () {
|
||||
if (base instanceof Function) {
|
||||
base.apply(this, arguments)
|
||||
}
|
||||
fn.apply(this, arguments)
|
||||
if (typeof base !== 'function') {
|
||||
return 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) {
|
||||
|
@ -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) {
|
||||
|
1
test/fixtures/module/modules/basic/index.js
vendored
1
test/fixtures/module/modules/basic/index.js
vendored
@ -15,6 +15,7 @@ module.exports = function basicModule (options, resolve) {
|
||||
// Extend build again
|
||||
this.extendBuild((config, { isClient, isServer }) => {
|
||||
// Do nothing!
|
||||
return config
|
||||
})
|
||||
|
||||
// Extend routes
|
||||
|
Loading…
Reference in New Issue
Block a user