R
R
Rustam Akimov2019-06-20 17:45:34
webpack
Rustam Akimov, 2019-06-20 17:45:34

How to replace a variable during application build?

Hi
When developing a project locally, I bind to an api that is running on the local host, when I build and upload the application, I need to replace this address with the real api address, is there a way to automate this, for example, to replace a variable during npm run build?
Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-06-20
@Inogami

environment variables

E
eremenkoEvgeniy, 2019-06-20
@eremenkoEvgeniy

1. npm i gulp-replace
2. replace -> inside task that builds js

A
Anton Spirin, 2019-06-20
@rockon404

If you are using your build:

module.exports = {
  plugins: [
    new webpack.DefinePlugin({
      __API__: JSON.stringify('http://my-api-service.com'),
    }),
  ],
};

If @vue/cli:
Environment variables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question