Quantcast
Channel: How to import files inside functions when using Vite (Vue 3, Nuxt 3) - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to import files inside functions when using Vite (Vue 3, Nuxt 3)

$
0
0

I have a question.

Regarding migration from Vue 2 => Vue 3 and Nuxt 2 => Nuxt 3, and the new use of Vite,the function require() is no more supported.

I have to migrate this function which is requiring files according to the language, but I see that it is not possible o use the sentence 'import' inside a javascript function.

Which would be the solution that I could apply in this case?

    export function getTranslationsByKey(key) {      const locales = LOCALES.map((locale) => {        const file = require('./'+ locale.iso +'/index.js')        return {          [locale[key]]: { ...file },        }  })

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>