A
A
Alex2020-08-02 14:45:31
JavaScript
Alex, 2020-08-02 14:45:31

How to get environment variable in js script?

I am making a project in which jquery is needed during development, but when building in production, it does not need to be inserted into the final bundle. I decided to import or do it according to the condition that if not prod then turn it on, otherwise not. But it doesn't work to get at least some environment variable. I collect everything with webpack. 2 commands in package.json are

"build": "webpack --mode production --colors --progress",
"start": "webpack-dev-server --mode development --hot --colors --progress

" theory, since I have fashions registered, I already have some kind of variable, but there is nothing, an empty object.
I tried to add the --env.VALUE parameter to the same command, and it doesn't exist.

Maybe there is another way to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-08-02
@pilolin

https://webpack.js.org/configuration/configuration...
https://webpack.js.org/api/cli/#environment-options

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question