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.
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/).
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".
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?
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.
For new version angular-cli, you should use the following command line:
MSYS2_ARG_CONV_EXCL="--base-href" npm run build -- --base-href="/mydir/"
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\\"
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 :)
I uses ng build --prod --base-href=//my-base-href and worked to me.
thanks @theredpea
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._
Most helpful comment
You're using
gitbash, and whengitbashreads/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/).