Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set --base-href by default for ng build, but not for ng serve?

What is the best way to set the --base-href for ng build by default, but not affect ng serve?

  • Angular CLI 1.6.6
  • Angular 5~
like image 967
ChekTek Avatar asked Feb 21 '18 00:02

ChekTek


1 Answers

Not directly, but you can define NPM scripts in your package.json:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --base-href=/path"
},

then you run the webpack server with npm start and can run the build with npm run build (note: NPM only recognizes some script names like start, where you can omit run)

You can also specify different build scripts, mine look like these:

"scripts": {
    "ng": "ng",
    "start": "ng serve --preserve-symlinks",
    "build": "ng build --base-href /static/frontend/ --output-path ../static/frontend --aot",
    "build-prod": "ng build --env=prod --prod --output-path dist-prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
},
like image 53
masterfloda Avatar answered Nov 16 '22 07:11

masterfloda