Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import Quasar language packs in Vite #12911

Closed
maggie44 opened this issue Mar 23, 2022 · 5 comments
Closed

Unable to import Quasar language packs in Vite #12911

maggie44 opened this issue Mar 23, 2022 · 5 comments

Comments

@maggie44
Copy link
Contributor

maggie44 commented Mar 23, 2022

What happened?

In Webpack, I would use the following to import languages from the quasar node_modules folder are per the Quasar docs:

      import(
        // https://quasar.dev/options/quasar-language-packs#dynamical-non-ssr-
        /* webpackInclude: /(en-US|de|fr|it|nb-NO|pt-BR)\.js$/ */
        `quasar/lang/${val}`
      )

It looks like import.meta.glob is the best proposed alternative but it isn't compatible with node_module imports: vitejs/vite#5728.

At the moment there doesn't seem to be a good way to import these languages from the node_modules folder other than by either symlinking or copying them across manually and storing them in the src/ folder somewhere: vitejs/vite#5728 (comment)

Ideally it would be useful to establish a 'best practice' for overcoming this issue in Quasar projects in Vite.

What did you expect to happen?

Be able to import the Quasar language files from node_modules so changes are pulled in to the app on a update automatically.

Reproduction URL

Not applicable

How to reproduce?

N/A

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

No response

Quasar info output

No response

Relevant log output

No response

Additional context

No response

@maggie44 maggie44 added kind/bug 🐞 Qv2 🔝 Quasar v2 issues labels Mar 23, 2022
@maggie44 maggie44 changed the title Importing Quasar language packs in Vite Unable to import Quasar language packs in Vite Mar 23, 2022
@github-actions
Copy link

Hi @Maggie0002! 👋

It looks like you provided an invalid or unsupported reproduction URL.
Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub.
Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc.
Please edit your original post above and provide a valid reproduction URL as explained.

Without a proper reproduction, your issue will have to get closed.

Thank you for your collaboration. 👏

@rstoenescu
Copy link
Member

First of all, for anyone reading, this is not a Quasar issue.
Secondly, I'll try to find some time to add instructions to the docs on how to achieve the same effect with q/app-vite.

@rstoenescu
Copy link
Member

Long story short (extract from my additions to the docs below). The examples are with boot files, but I think you can infer how to use in vue files also.

  1. Non-SSR
// -- With @quasar/app-vite --

import { Quasar } from 'quasar'

// relative path to your node_modules/quasar/..
// change to YOUR path
const langList = import.meta.glob('../../node_modules/quasar/lang/*.mjs')
// or just a select few (example below with only DE and FR):
// import.meta.glob('../../node_modules/quasar/lang/(de|fr).mjs')

export default async () => {
  const langIso = 'de' // ... some logic to determine it (use Cookies Plugin?)

  try {
    langList[ `../../node_modules/quasar/lang/${ langIso }.mjs` ]().then(lang => {
      Quasar.lang.set(lang.default)
    })
  }
  catch (err) {
    // Requested Quasar Language Pack does not exist,
    // let's not break the app, so catching error
  }
}
  1. SSR
    Mostly same thing, only that Quasar.lang.set requires a second parameter. Quasar.lang.set(lang.default, ssrContext)

@rstoenescu
Copy link
Member

e532388

@maggie44
Copy link
Contributor Author

Looks good, an adapted version using the same method seems to be working for me. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants