When building a PWA, angular let us specify the folder it's served from :
ng build --prod --base-href=/www/
The command
ionic build --prod --base-href=/www/
should recognise the --base-href option, but ignores it.
Ionic:
ionic (Ionic CLI) : 4.1.2 (C:\Users\User\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.11
@angular-devkit/core : 0.8.3
@angular-devkit/schematics : 0.8.3
@angular/cli : 7.0.0-beta.4
@ionic/ng-toolkit : 1.0.8
@ionic/schematics-angular : 1.0.6
Cordova:
cordova (Cordova CLI) : 7.0.1
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (1 plugins total)
System:
NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10
Did this on purpose, originally. Most low-level Angular CLI options are ignored. If --base-href is used with ionic cordova commands, the app breaks.
We'll need to give this some thought for standard web builds.
Thanks for the issue!
It worked for me with the command: ionic build --prod -- --base-href /www/
@SimonGolms Yep, that's a good workaround for now. I think a true PWA integration will be preferred.
Is there a way to build it without the base href? I'll be hosting an app at domain.com/app/ directory. Don't know if it's safe to just remove it (considering routes use something like /pagename etc.).
Update: If someone else fall here for the same thing, I just changed <base href="/" /> of src/index.html to <base href="./" />. Apparently all working good for now.
Update 2: Nope, don't do that, <base href="./" /> will fuck up endpoints like 麓/app/a/b/c`.
@giovannipds Unfortunately, <base href> is required by the Angular Router if you're using HTML5 routing, which is the default. It needs to know how to get back to the "base" path for a SPA.
Thanks @dwieeb. @SimonGolms's tip works. =D
A quick question: the empty -- is a way to pass the flag to ng, did I get it right?
Don't know if this issue should be maintained open if there's this workaround.
the empty
--is a way to pass the flag tong, did I get it right?
Yeah, it's like a separator for options. Other CLIs use this convention, including Cordova and git (sort of). This is explained in the help output: ionic build --help.
Don't know if this issue should be maintained open if there's this workaround.
My plan was to keep it open until we can suitably abstract this option. Because Ionic can target multiple platforms, such as Cordova, PWAs, and web, some options may need to be different per target platform. For example, Cordova should use --base-href=/, and PWA may use --base-href=app/, or similar. Because of this, we should abstract this low-level option. Hopefully devs won't need to worry about it.
So I'll merge this issue into https://github.com/ionic-team/ionic-cli/issues/2664, which will require some thought about base href before completion.
The workaround should be good enough for now. Thanks everyone!
Hello, It changed in the last version. This works for me:
ionic build --prod --public-url=/app/
Most helpful comment
It worked for me with the command:
ionic build --prod -- --base-href /www/