I'm a newbie in angular trying to pass a parameter to my angular build process.
I want to build my app for a specific client so I'm using npm variables to copy the client settings:
npm run build --client=cocacola
However, I cannot figure out how to pass my client name (e.g: cocacola) to my angular.js
This is my scripts in package.json
"scripts": {
"ng": "ng",
"start": "ng serve",
"prebuild": "cp src/app/clients/$npm_config_client.settings.ts src/app/app.settings.ts",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
This is part of my angular.json
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
{"glob": "**/*", "input" : "src/$npm_config_client/assets", "output": "/assets/"}
],
"styles": [
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
},
Where I'm trying to use my --client
in options/assets
to load specific client assets.
{"glob": "**/*", "input" : "src/$npm_config_client/assets", "output": "/assets/"}
Is it possible to do this in Angular?
I also created one angular.json per each client but there has to be a better way.
Have you tried to use "configuration"?
Like this: