Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build to Output path based off environment

I am trying to figure out how to build and deploy an Angular 2 project built with angular cli based off of variables in my environment typescript files.

For example, my angular-cli.json file has a dev environment declared that points to "environments/environment.dev.ts". This file has the following properties:

export const environment = {
  production: false,
  'output-path': '\\\\testServer\\apps\\appName\\'
};

What I would like to do is be able to call ng build --dev, and the cli would build the app with the dev file (which it does correctly), but also output it to the output-path, which in this case would be a network share. Is there anyway to do this without incorporating some other CI tool and/or gulp?

I have manually added the -o (--output-path) option when building and passed the path, but I don't want to build a solution for the company that would require developers to manually type paths each time.

I am aware I could update the package.json to add new commands for build/deploy with the --output-path parameter, but that would require updating the paths in multiple files and adding lots of new commands (ones for local, dev, test, prod).

Does anyone have a good solution for this?

like image 762
Geo Avatar asked Dec 22 '16 18:12

Geo


2 Answers

Update for Angular 6+:

Set it in the angular.json:

For the development env:

  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/dev",

For the production env:

      "configurations": {
        "production": {
          "outputPath": "dist/prod",
like image 107
JohnnyDevNull Avatar answered Oct 21 '22 09:10

JohnnyDevNull


There are flags for the ng build command to handle what you need...

--target=development (or -dev)
--target=production (or -prod)
&
--output-path=my/output/path

So you can create npm scripts to do them in conjuction:

//in package.json
"scripts": {
  "devbuild": "ng build -dev --output-path=my/dev/output",
  "prodbuild": "ng build -prod --output-path=my/prod/output"
}

then you can just run....

npm run devbuild
npm run prodbuild
like image 23
Brocco Avatar answered Oct 21 '22 09:10

Brocco