Cannot use env var with Angular

Viewed 35

I'am tryng to set env var in environnement.ts to set url with the rigth env. attempt 1 var is not loaded

export const environment = {
  production: false,
  API_URL :'http://myapp.api.${MYENV}.xx.test.xx.xx.xx/'

--

MYENV =test

 **Result**:
    Request URL: http://myapp.api.%24%7Bmyenv%7D.xx.test.xx.xx.xx/xx/xxxxxxx

attempt 2: Create environnement.ts for all environement ( test - dev - qa - ppd - prd ) Adding bloc for all environnement

Angular.json

                    "prd": {
                        "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prd.ts"
                            }
                    "test": {
                        "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.test.ts"
                            }
                    "dev": {
                        "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.dev.ts"
                            }
etc ...

select with build --test option which environment will be used.

FROM node:14.15.4 AS build
ARG  
RUN npm config set registry "http://xxx.xxx.xxx.xxxx/api/npm/npm/"
RUN mkdir -p /test/

WORKDIR /test/
RUN npm cache clean --force

COPY ./src/main/frontend/ /test/

RUN npm install --verbose

WORKDIR /test/
RUN npm run build --test

build with option --test seem's not working only environment.ts is loading and environment.test.ts is ignored.

Any idea ?

1 Answers

add this line in Dockerfile

RUN npm run build -- --configuration=test

I will put env for environnement test ppd prd etc for deploy with env var setted in server to automatise deploy without change the ligne manually in the dockerfile

Attempt 1 with var env in the environment.test.ts seem's not be implemented by Angular

Related