Vue config async support
See original GitHub issueWhat problem does this feature solve?
Allow for asynchronous actions within vue.config.js. The specific use-case I’m looking at right now is the need to prerender dynamic routes based on data returned by an api. I’m found a few things online but nothing that appears to work with vue cli 3.x
What does the proposed API look like?
Await the result of the configureWebpack
or chainWebpack
methods:
const path = require('path')
const axios = require('axios')
const PrerenderSPAPlugin = require('prerender-spa-plugin')
module.exports = {
configureWebpack: async () => {
const { data } = await axios.get('http://some-api.com/companies')
const { companies } = data
return {
plugins: [
new PrerenderSPAPlugin({
// Required - The path to the webpack-outputted app to prerender.
staticDir: path.join(__dirname, 'dist'),
// Required - Routes to render.
routes: [ '/' ].concat(companies.map(company => `/companies/${company}`))
})
]
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:27
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Asynchronous Loading of vue.config.js for Pre-Rendering ...
The configureWebpack option doesn't support Promises yet, meanwhile you can fetch the data before running the build.
Read more >Async Components - Vue.js
The resulting AsyncComp is a wrapper component that only calls the loader function when it is actually rendered on the page. In addition,...
Read more >How to Use Async and Await with Vue.js Apps - Medium
async and await are great ways to chain promises. The syntax is much more convenient than chaining then functions. The only thing you...
Read more >Coding Better Composables: Async Without Await (5/5)
The setup function will return when it runs into an await statement. ... Let's see how some VueUse composables implement this pattern.
Read more >Handling Asynchrony in Vue 3 / Composition API
If Suspense is about to be used, we can start right away with using async / await directly in the setup function: But...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That could make sense, but would also be a lot of work and possibly a breaking change. We will have to have a thorough look at this.
Meanwhile, you can use a local plugin file to write your own wrapper around
build
and do the async fetching before actually running build:package.json:
build.prerender.js
Usage in package.json:
If need both
build:async
andserve:async
, currently, I have to… (invue.async.config.js
)There should be a single Vue Config object, therefore, a more elegant way to do this…