Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng build --base-href #5606

Closed
naveenacharya1 opened this issue Mar 24, 2017 · 9 comments
Closed

ng build --base-href #5606

naveenacharya1 opened this issue Mar 24, 2017 · 9 comments

Comments

@naveenacharya1
Copy link

naveenacharya1 commented Mar 24, 2017

I am using "@angular/cli": "1.0.0-rc.2",

when I do ng build --base-href /myapp/

it generates me an index.html with C:/Users/myname/.webclipse/git-bash/myapp/

Ex :

expected is :

Please advice.

@filipesilva
Copy link
Contributor

You're using gitbash, and when gitbash reads /myapp/ it converts the path. There's not much we can do in the CLI about that. You can try using a two slashes instead, that should work (--base-href //myapp/).

@nickmarinho
Copy link

nickmarinho commented Feb 8, 2018

Two slashes reproduces "//my-folder" as is.
While "/my-folder" reproduces "c:\path\to\my-folder"
I'd tried too: "/my-folder"

And same result: "c:\path\to\my-folder".

@daiplusplus
Copy link

daiplusplus commented Feb 14, 2018

I'm not convinced that gitbash is the sole cause of this problem:

$ basepath=/foo/
$ which echo        # checking to see we're using an exe for echo instead of a shell built-in...
/usr/bin/echo         # ...indeed, this is an actual exe at C:\Program Files\Git\usr\bin
$ echo foo=$basepath
foo=/foo/        # so we see that echo.exe received, and forwarded, the expanded variable $basepath fine
$ ng build --base-href $basepath
$ head dist/index.html
<!DOCTYPE ...><base href="C:/Program Files/Git/foo" />... $ but it was incorrectly expanded here

So if gitbash really is to blame, how come echo.exe received the expanded variable successfully?

@tolgabalci
Copy link

See this for when conversions occur:
http://www.mingw.org/wiki/Posix_path_conversion

You can tell git bash to avoid the conversion for the -bh parameter by setting the MSYS2_ARG_CONV_EXCL environment variable while calling ng like this:
MSYS2_ARG_CONV_EXCL="-bh=" ng build --prod -bh="/en/"

Note that to use the exclusion you must use -bh parameter with an =, not space since MSYS2_ARG_CONV_EXCL will think the value after the space is a different parameter.

@jixuyang
Copy link

jixuyang commented Jun 7, 2018

For new version angular-cli, you should use the following command line:
MSYS2_ARG_CONV_EXCL="--base-href" npm run build -- --base-href="/mydir/"

@theredpea
Copy link

theredpea commented Jun 14, 2018

Per @tolgabalci link

An argument starting with 2 or more / is considered an escaped Windows style switch and will be passed with the leading / removed and all \ changed to /.

I use gitbash to run my angularApp.sh bash script;
My bash script looks like this; note the two leading slashes (to meet the above rule) and the escaped backslash:

ng build --watch --output-path=../dist/site --base-href="//site\\"

If doing multiple levels:
ng build --watch --output-path=../dist/site --base-href="//site-area\\site\\"

@drewwiens
Copy link

MSYS2_ARG_CONV_EXCL="--base-href" npm run build -- --base-href="/mydir/"

This was the best solution for us. It allows us to create a bash script that accepts any base-href as a command-line argument and builds the project. Note this method does not appear to work with yarn though! We use yarn for everything else in our project, but for this we had to use "npm run build" rather than "yarn build" -- I almost disregarded this method because I couldn't get it to work with yarn. Hopefully this helps someone :)

@HigorSenna
Copy link

I uses ng build --prod --base-href=//my-base-href and worked to me.
thanks @theredpea

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants