我在路径“ src / config.js”下有一个带有API URL的配置文件:
const API_URL = 'https://some-url-here.com'
export default {
API_URL: API_URL
}
还有一个Dockerfile:
# build stage
FROM node:9.11.1-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:1.13.12-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
我如何使API_URL
可用于docker,以便devops可以更改该URL?
答案 0 :(得分:2)
使用Vue-cli 2.9,您可以在“ config”目录中设置ENV变量。
例如:“ config / dev.env.js”:
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
API_URL: '"https://server.com"'
})
然后您可以在客户端中使用它:
const API_URL = process.env.API_URL
export default {
API_URL: API_URL,
}