No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to inject value/variable into JS

    Framework
    3
    5
    1415
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      imatmati last edited by

      Hi,

      I’m looking for a way to inject a value/variable in the application in the build process according target environments. For instance, I’d like to inject the dev address of an API for a dev application, the prod address of an API for a prod application, etc.
      I gathered I could use webpack to do that. But unfortunately, every example I tried failed. Is there any reference for doing that from webpack or any other means ?
      Have a nice day.

      1 Reply Last reply Reply Quote 0
      • I
        imatmati last edited by

        Never mind, I found the solution. Here it is
        extendWebpack (cfg) { cfg.plugins.push(new webpack.DefinePlugin({ API: JSON.stringify("http://api.dev.com:3949/superservice") })) }
        Not sure, if this is the best solution, but it worked. Now I can reference directly the API variable in my js code.

        1 Reply Last reply Reply Quote 2
        • a47ae
          a47ae last edited by

          The cleaner solution would be to use env variables: http://quasar-framework.org/guide/quasar-upgrade-guide.html#We-were-using-different-env-for-dev-and-production
          Then you can access your variables with process.env.MY_VARIABLE

          1 Reply Last reply Reply Quote 2
          • rstoenescu
            rstoenescu Admin last edited by

            http://quasar-framework.org/guide/app-quasar.conf.js.html#Example-setting-env-for-dev-build

            1 Reply Last reply Reply Quote 1
            • I
              imatmati last edited by

              Hi,

              Thanks, I 'll have a look at your recommendations.
              And special thanks to rstoenescu for your great work. Currently, I’m trying to establish for a (big) firm that your framework would be the right one for them. Have you something like a comparison between plain vue.js and your framework with pros and cons ?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post