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(
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) => {