Nuxt.js: Async data inside nuxt.config.js

Created on 28 Sep 2018  路  2Comments  路  Source: nuxt/nuxt.js

What problem does this feature solve?

Currently there is no nice way how to use async data inside nuxt.config.js.
For example getting some module configuration from remote server, getting head data, list of plugins that need to be enabled for current build etc.

This would allow to use same Nuxt app for multiple similar sites but with slight difference of configuration that is changeable from remote admin panel.

What does the proposed changes look like?

Something like this (quite pseudocode)

// nuxt.config.js

const getHeadConfig = async () => {
  let { data } = await axios.get('/my/head/config/url')
  return {
    ...data,
    title: 'hurrdurr'
  }
}

module.exports = {
  mode: 'universal',

  // Get conf from remote with axios
  loading: axios.get('/my/loading/config/url'),

  // Use some method to get data from remote
  head: getHeadConfig()
}

This feature request is available on Nuxt community (#c7860)
available soon feature-request

Most helpful comment

I think this problem could be tackled as we do it with modules, plugin etc.

If the export of nuxt.config.js is a function, we should call and await it. 馃

export default async () => {
    const data = await otherFn()
    return {
        head: "...",
        ...data
    }
}

All 2 comments

I think this problem could be tackled as we do it with modules, plugin etc.

If the export of nuxt.config.js is a function, we should call and await it. 馃

export default async () => {
    const data = await otherFn()
    return {
        head: "...",
        ...data
    }
}

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pehbehbeh picture pehbehbeh  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments

msudgh picture msudgh  路  3Comments

lazycrazy picture lazycrazy  路  3Comments