A
A
asd dsa2019-12-06 20:24:47
JavaScript
asd dsa, 2019-12-06 20:24:47

How to make a condition on the passed argument from the console?

There package.jsonis a script dev, I run it yarn run dev, as a result, the project is built and launched on the localhost. How to implement the ability to pass an argument from the console, for example: yarn run dev --test, so that later, for example, in App.vuemaking a condition for a variable, for example: process.argv === 'test' ? 1 : 0. When I do it console.log(process)in a hook createdin a component App.vue, the array argv is empty for some reason. Please tell me how to implement this without using additional libraries, such as yargs, minimize, etc ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2019-12-07
@yaNastia

In Vue, you can define your environment variables only starting with VUE_APP_
Well, then in the console something like this:
VUE_APP_TEST=test yarn dev(depending on the current OS)
And in the application we look inprocess.env.VUE_APP_TEST

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question