refacotr: reduce duplicate call of plugins getter

This commit is contained in:
Clark Du 2018-08-10 15:59:15 +01:00
parent 960f4fe47e
commit 4472a5003e

View File

@ -64,7 +64,7 @@ export default class Builder {
// } // }
} }
get plugins() { normalizePlugins() {
return _.uniqBy( return _.uniqBy(
this.options.plugins.map((p) => { this.options.plugins.map((p) => {
if (typeof p === 'string') p = { src: p } if (typeof p === 'string') p = { src: p }
@ -156,6 +156,8 @@ export default class Builder {
async generateRoutesAndFiles() { async generateRoutesAndFiles() {
consola.debug(`Generating nuxt files`) consola.debug(`Generating nuxt files`)
this.plugins = this.normalizePlugins()
// -- Templates -- // -- Templates --
let templatesFiles = [ let templatesFiles = [
'App.js', 'App.js',
@ -445,14 +447,10 @@ export default class Builder {
// Check plugins exist then set alias to their real path // Check plugins exist then set alias to their real path
await Promise.all(this.plugins.map(async (p) => { await Promise.all(this.plugins.map(async (p) => {
if (!await fsExtra.pathExists(p.src)) { if (!await fsExtra.pathExists(p.src)) {
throw new Error(`Plugin not found: ${r(p.src)}`) throw new Error(`Plugin not found: ${p.src}`)
} }
}))
// Alias plugins to their real path
this.plugins.forEach((p) => {
const src = this.relativeToBuild(p.src) const src = this.relativeToBuild(p.src)
// Client config // Client config
if (!clientConfig.resolve.alias[p.name]) { if (!clientConfig.resolve.alias[p.name]) {
clientConfig.resolve.alias[p.name] = src clientConfig.resolve.alias[p.name] = src
@ -463,7 +461,7 @@ export default class Builder {
// Alias to noop for ssr:false plugins // Alias to noop for ssr:false plugins
serverConfig.resolve.alias[p.name] = p.ssr ? src : './empty.js' serverConfig.resolve.alias[p.name] = p.ssr ? src : './empty.js'
} }
}) }))
// Configure compilers // Configure compilers
this.compilers = compilersOptions.map((compilersOption) => { this.compilers = compilersOptions.map((compilersOption) => {