angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build --base-href

Open naveenacharya1 opened this issue 9 years ago • 9 comments

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.

naveenacharya1 avatar Mar 24 '17 02:03 naveenacharya1

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/).

filipesilva avatar Mar 24 '17 02:03 filipesilva

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".

nickmarinho avatar Feb 08 '18 16:02 nickmarinho

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?

daiplusplus avatar Feb 14 '18 00:02 daiplusplus

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.

tolgabalci avatar May 31 '18 00:05 tolgabalci

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

jixuyang avatar Jun 07 '18 07:06 jixuyang

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\\"

theredpea avatar Jun 14 '18 21:06 theredpea

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 :)

drewwiens avatar Oct 18 '18 21:10 drewwiens

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

HigorSenna avatar Oct 20 '18 22:10 HigorSenna

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.