How can I know the Vue.js environment is development or production ?
In my AxiosConfig
's config.js
:
AxiosConfig:{
baseURL:dev.NODE_ENV.BASE_API,
responseType: "json",
withCredentials: true,
...
You see the BASE_API
in there:
there is the definition of dev.NODE_ENV
:
dev.NODE_ENV = {
BASE_API: 'http://localhost:8000',
APP_ORIGIN: 'http://103.20.32.16:8000/'
}
How can I check the environment is development or production?
then in the AxiosConfig
config.js I can use the judgement, when npm run build I will not need to change the
baseURL` then.
Take a look at process.env.NODE_ENV
and test for development
or production
. You might want to replace your dev.NODE_ENV.BASE_API
with something like process.env.NODE_ENV.BASE_API
.
Further to this, if you're using the vue-cli-service
to bootstrap and build your app, you can use .env
files and switch the baseURL
using those, depending upon your environment. You can find out about it in more detail here: https://cli.vuejs.org/guide/mode-and-env.html
像往常一样,当您运行命令npm run dev时 ,它将是一个webpack开发服务器;如果您运行npm run build ,则将用于生产,并且它将在dist文件夹中生成它的缩小版本。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.