Angular-cli: npm run ng build --base-href /newapp not working

Created on 30 Mar 2017  Â·  7Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

_ng build --base-href /newapp_ works correctly and replaces the base-href in index.html as desired, but when run with _npm run_ does not replaces the base-href in index.html file

Versions.

@angular/cli: 1.0.0
node: 7.5.0
os: win32 x64
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

Repro steps.

npm run ng build --base-href /newapp

The log given by the failure.

C:\dev\workspaces\ng-app>npm run ng build --base-href /newapp

> [email protected] ng C:\dev\workspaces\ng-app
> ng "build" "/newapp"

Hash: fcb666bc392e9f834161
Time: 7355ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 3.68 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 9.77 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.06 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

C:\dev\workspaces\ng-app>ng build --base-href /newapp
Hash: fcb666bc392e9f834161
Time: 8058ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 3.68 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 9.77 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.06 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

Desired functionality.


Expected npm run ng build --base-href /newapp and ng build --base-href /newapp to behave same.

Mention any other details that might be useful.


I am using it it with maven-frontend-plugin which takes "ng build --base-href /newapp" as argument to goal "npm run"

It looks like optional parameters are not being passed and issue may not be limited to --base-href

Most helpful comment

When running npm scripts and you want to send flags, you have to separate the command flags with --:

npm run ng -- build --base-href /newapp

This is how npm run works and not a particular of Angular CLI. See https://docs.npmjs.com/cli/run-script for more information.

All 7 comments

@jbhardwaj12 You can add the new script in package.json as "run:dev": "ng b --base-href /newapp" and do npm run run:dev this should work fine.

That will work as workaround for one application. In fact what we are trying to do is slightly more.

The reason I am trying to pass the "Tomcat Context" to run app on via Maven. This will enable app to be used my two or multiple clients with each one having its own context. This way build process will take care of specific required context per client for multi-tenant environment.
Similarly "client" and "admin" apps can be run on separate contexts.

Also, as stated in last line of issue description - It looks like the optional arguments are being ignored when used "npm run" - it may be a bigger issue and this may be the real cause of --base-href not working. I was not able to confirm it though.

The --prod, --target, and --environment flags are ignored as well. My usecase is pretty close to what jbhardwaj12 is trying to do. Additionally, the reason I don't want to install the CLI globally is because that will add one more system-level dependency that needs to be updated and maintained by the sys-admin team.

They already think that I'm a hipster programmer because I started using Node.JS to bundle my application. Anything that could be done to fix this would be very much appreciated!

When running npm scripts and you want to send flags, you have to separate the command flags with --:

npm run ng -- build --base-href /newapp

This is how npm run works and not a particular of Angular CLI. See https://docs.npmjs.com/cli/run-script for more information.

I ended up using this as my deploy script:
ng build –prod –aot && sed -i -e 's/href=\"\\/\"/href=\"\\/ScrumTimer\\/\"/g' ./dist/index.html && cp ./dist/index.html ./dist/404.html && angular-cli-ghpages –-no-silent

I think the main issue for me is that the package.json npm commands are chained:

"build:client-and-server-bundles": "ng build --prod && ng build --prod --app 1 --output-hashing=false",

So the params passed though seem to only apply to the second command:

npm run build:client-and-server-bundles -- --base-href http://angular-universal-example.s3-website-us-east-1.amazonaws.com

I see it run as:

ng build --prod && ng build --prod --app 1 --output-hashing=false "--base-href" "http://angular-universal-example.s3-website-us-east-1.amazonaws.com"

See how the param is passed through to the second chained command?

My workaround is to run the commands separately:

ng build --prod --base-href http://angular-universal-example.s3-website-us-east-1.amazonaws.com
ng build --prod --app 1 --output-hashing=false --base-href http://angular-universal-example.s3-website-us-east-1.amazonaws.com
npm run webpack:server && npm run generate:prerender

Would be great to have a solution where passing one command to npm run would run all all chained commands

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hartjo picture hartjo  Â·  3Comments

brtnshrdr picture brtnshrdr  Â·  3Comments

donaldallen picture donaldallen  Â·  3Comments

sysmat picture sysmat  Â·  3Comments

MateenKadwaikar picture MateenKadwaikar  Â·  3Comments