mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 03:38:07 +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)) {
|
if (!(fn instanceof Function)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return function () {
|
if (typeof base !== 'function') {
|
||||||
if (base instanceof Function) {
|
return fn.apply(this, arguments)
|
||||||
base.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) {
|
export function isPureObject (o) {
|
||||||
|
@ -74,25 +74,7 @@ export default class ModuleContainer extends Tapable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extendRoutes (fn) {
|
extendRoutes (fn) {
|
||||||
const extendRoutesFromConfig = this.options.router.extendRoutes
|
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requireModule (moduleOpts) {
|
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
|
// Extend build again
|
||||||
this.extendBuild((config, { isClient, isServer }) => {
|
this.extendBuild((config, { isClient, isServer }) => {
|
||||||
// Do nothing!
|
// Do nothing!
|
||||||
|
return config
|
||||||
})
|
})
|
||||||
|
|
||||||
// Extend routes
|
// Extend routes
|
||||||
|
Loading…
Reference in New Issue
Block a user