From 4472a5003e36a3a587e108e6ac3ea30374a989dc Mon Sep 17 00:00:00 2001 From: Clark Du Date: Fri, 10 Aug 2018 15:59:15 +0100 Subject: [PATCH] refacotr: reduce duplicate call of plugins getter --- lib/builder/builder.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 1c3e00dacd..92293c05f8 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -64,7 +64,7 @@ export default class Builder { // } } - get plugins() { + normalizePlugins() { return _.uniqBy( this.options.plugins.map((p) => { if (typeof p === 'string') p = { src: p } @@ -156,6 +156,8 @@ export default class Builder { async generateRoutesAndFiles() { consola.debug(`Generating nuxt files`) + this.plugins = this.normalizePlugins() + // -- Templates -- let templatesFiles = [ 'App.js', @@ -445,14 +447,10 @@ export default class Builder { // Check plugins exist then set alias to their real path await Promise.all(this.plugins.map(async (p) => { 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) - // Client config if (!clientConfig.resolve.alias[p.name]) { clientConfig.resolve.alias[p.name] = src @@ -463,7 +461,7 @@ export default class Builder { // Alias to noop for ssr:false plugins serverConfig.resolve.alias[p.name] = p.ssr ? src : './empty.js' } - }) + })) // Configure compilers this.compilers = compilersOptions.map((compilersOption) => {