Different .env.development configurations in Vue bundled with Webpack

I'm having trouble figuring out how to set up two different configurations for my Vue.js project on my local environment using vue-cli 3.

The first configuration should have VUE_APP_API_URL pointing to my localhost, while the second configuration should connect to a development/staging server.

  • I'm thinking of using .env.development-1 and .env-development-2 to achieve this, allowing me to easily switch between the two configurations without much hassle.

While I've come across information about build modes, most of them focus on building the project. All I want is to run the local dev server with a different configuration. Can anyone guide me on how to accomplish this?

Answer №1

After receiving helpful comments on my initial post, I discovered that the solution was actually quite simple:

All I had to do was create an .env.staging file with the VUE_APP_API_URL set to the staging server, leaving everything else unchanged.

Then, I updated my scripts in the package.json file as follows:

"scripts": {
    "serve:local": "vue-cli-service serve",
    "serve:staging": "vue-cli-service serve --mode staging",
}

And it worked like a charm.

Initially, I had to wrap my head around the concept, but with the help provided, I was able to successfully implement the solution. Thank you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing Vue 3 reactivity using Provide/Inject versus accessing default slots with this. $slots.default

I am currently in the process of contributing to the PR for primefaces/primevue repository. The goal is to enable wrapping Column components within custom components for the DataTable. The PR introduces a new way for Column components to register themselve ...

Identify the absence of search results in an Ajax request to the search page before rendering the HTML content

I am attempting to retrieve JSON code from a page using the following PHP function: private function __ajax_admin_search($username = '') { $result = $this->admin_login->Admin_Username_Ajax($username); $count = count($result); for ...

What is the best way to trigger a function exclusively upon clicking a particular element?

My goal is to enable the user to interact with the model by positioning cubes in space upon clicking the "Cubes Mode" button. I currently have a script from the three.js website that achieves this, but I want it to only run when the mentioned button is cli ...

Error: Route configuration must include a "path" in [vue-router]

I found an official example that I'm trying to follow, but I keep getting a blank page with a JavaScript error. vue-router.esm.js?fe87:10 Uncaught Error: [vue-router] "path" is required in a route configuration. Below are the two pages I am workin ...

Set up a trigger to activate when a WordPress User Role is selected, or alternatively, execute JavaScript

Looking for a solution to detect when a new user is created with a custom User Role set to lessee. Options include adding a trigger through WordPress filters or actions, or detecting the change in JavaScript using an event listener. I have identified the ...

Transform JavaScript into Native Code using V8 Compiler

Can the amazing capabilities of Google's V8 Engine truly transform JavaScript into Native Code, store it as a binary file, and run it seamlessly within my software environment, across all machines? ...

What are some ways to reduce the delay of Dark mode on a website?

Can anyone help me optimize the speed at which dark mode is applied on my website? Currently, there seems to be a delay between page load and the dark mode taking effect. Below is the jQuery.js code I am using: onload = function () { if (localStorage. ...

JavaScript causing values to disappear when the page refreshes

When a user hovers over ImageButtons, I use Javascript to change the ImageUrl. However, on submitting the form, the updated ImageUrl property is not reflected in the code behind. Similarly, I also dynamically update a span tag using Javascript, but its alt ...

VueJS not displaying OpenLayers map

I am having an issue with my Openlayers map in a .vue file. The code generates no errors, but the map is not displaying as expected. I have tried using two different vue plugins for Openlayers, but they didn't work for my specific needs. Interesting ...

What triggers Vue 2 to evaluate a "get" function/property?

Working with Vue recently, specifically Vue 2, has led me to question how Vue handles checking property values and triggering re-renders. I have multiple components in my application where the visibility is controlled by a method tied to a computed proper ...

Ensuring AngularJS ui-router/app waits for $http data to avoid Flash of Unstyled Content (FOUC)

My question or situation pertains to the states defined in my AngularJS application. Here is an example of how I have them structured: $stateProvider .state('myApp', { abstract: true, template: '& ...

Randomly generated numerical value in input field

How can I generate a 15-digit number using JS code and then reduce it to just 5 or 6 digits in a text box? <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript ...

Is it possible to execute a function when the AJAX request is successful and returns a status code of

I am looking to implement the success function to only run a certain function if the status code is 200. I have come across this example: $.ajax ({ success: function(data,textStatus,jqXHR){ external(); } )}; However, I have not found a clear ...

Angular - Implementing an Object Mapping Feature

Looking to dynamically generate parameter objects in Angular with a structure like this: [ password: {type: 'String', required: true, value: 'apassword'}, someRandomParam: {type: 'Integer', required: false, value:3} ] ...

Incorporating trail markers in your Vue.js app

Currently I'm working on implementing breadcrumbs for my Vue.js application. I am using a store component where I can access the current value and back state, but I am struggling to determine how to obtain the path between pages for the breadcrumbs. M ...

Tips for transferring large data without a page redirect using jQuery's post method:

Seeking advice on how to send large data via jQuery POST without redirecting the page. I'm working on a mobile chat project where communication between user app and server is done using JSON. The issue arises when dealing with big data as the jsonGet ...

I require my two elements to possess opposing transformations in their coordinates or directions to enable dragging capabilities

Changing the code to move the elements in opposite directions is my goal. I attempted multiplying the second element by -1, but unfortunately, I keep ending up with a NAN or undefined result. Any suggestions on how to achieve the desired effect? ...

Unable to launch React Native project on emulator now

Something seems off with my App as it won't start up on my AS Emulator. Everything was running smoothly yesterday, but today it's not working - possibly due to me moving the npm and npm-cache folders, although they are configured correctly with n ...

What could be causing my router UI in angular.js to malfunction?

Having an issue with routing not functioning as intended, here is the relevant code: $urlRouterProvider. otherwise('/list'); $stateProvider. state('home', { abstract: true, views: { 'header': { templateUrl: &apos ...

Why is it that consolidating all my jQuery plugins into one file is ineffective?

Prior to this, I included the following scripts: <script type="text/javascript" src="{{MEDIA_URL}}js/plugins/json2.js"></script> <script type="text/javascript" src="{{MEDIA_URL}}js/plugins/jquery-msdropdown/js/jquery.dd.js"></script&g ...