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

feat: implement --base-href argument #1506

Closed
wants to merge 2 commits into from

Conversation

dzonatan
Copy link
Contributor

@dzonatan dzonatan commented Jul 31, 2016

Closes #1064

Implement --base-href argument for build and github-pages:deploy commands.
Works as described in this comment.

One thing I did not fulfil from @filipesilva comment is:

the github deploy feature already does a regex base replacement, so it needs to be changed to use this feature

Everything I found was "updateBaseHref" method which uses this /<base href="\/">/g regex. After investigation it turns out that it will only replace the current <base href="/"> (it must be declared this way in your index.html otherwise it won't work) tag. Also I don't get why regex g modifier is used when base tag can be only one per page. Therefore I made my own regex to meet the insert whole tag (if not exists) & replace only href (if exists) requirements.

@frapontillo
Copy link

Awesome work! Can't wait to see it merged in.

@filipesilva
Copy link
Contributor

@dzonatan my apologies, I took too long to review this PR and meanwhile there were some big changes in the files you edited. I looked through your test suite and it looks good. Can you rebase to the latest master?

Also, can you add the --base-href option to this command, and pass on the option to build? https://github.com/angular/angular-cli/blob/master/addon/ng2/commands/github-pages-deploy.ts

@dzonatan
Copy link
Contributor Author

Done. Also added -bh alias for --base-href if you don't mind.

```bash
# Sets base tag href to /myUrl/ in your index.html
ng build --base-href /myUrl/
ng serve --base-href /myUrl/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have this flag in the serve command? I'd expect the app to not work since the Dev server isn't aware of it. Haven't tested though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh. You're right! The given example will not work as expected.
I was just thinking about the opposite case: when using production value in index.html and you need to override it back to "/" when developing. But seems that would be the only working case. So I will remove it form serve and rebase master.

@filipesilva
Copy link
Contributor

Left a question but otherwise lgtm!

@dzonatan dzonatan force-pushed the webpack-feature-basehref branch from 35413c6 to 8dd2cfe Compare August 24, 2016 17:48
@dzonatan
Copy link
Contributor Author

@filipesilva updated according to your comments

@filipesilva
Copy link
Contributor

Ah there's something else that I remembered now: the github deploy command does it's own base tag replacement:

https://github.com/dzonatan/angular-cli/blob/8dd2cfe53e90ddffa308eceb444b973d05f61331/addon/ng2/commands/github-pages-deploy.ts#L207-L216

This logic needs to go into the build options now. Basically, if options.userPage is true, then we don't auto-replace the tag. Otherwise, it needs to be replaced with the project name since that's the base for github pages projects.

You'll probably want to have the --base-href flag take priority over that logic though, in case people want to force a certain tag.

Also, these tests should now not try and test the base href functionality, since that's part of the build task now (and I can't imagine a good way to test it from within this test anymore):
https://github.com/dzonatan/angular-cli/blob/8dd2cfe53e90ddffa308eceb444b973d05f61331/tests/acceptance/github-pages-deploy.spec.js#L86

There's a few instances of this check mind you.

@dzonatan dzonatan force-pushed the webpack-feature-basehref branch from 8dd2cfe to c159363 Compare August 25, 2016 08:22
@dzonatan
Copy link
Contributor Author

I'm not the expert of github pages so here some questions:

  1. As I understood from fix(gh-deploy): fix deep links #1020 PR this line in updateBaseHref is still needed and should be left as separate deployment step. Right?
  2. Should this line in printProjectUrl be somehow modified according to --base-href logic?

Anyway, I pushed a new commit for easier review. Please look at it.


let lastHash: any = null;

module.exports = Task.extend({
run: function(runTaskOptions: ServeTaskOptions) {
run: function(runTaskOptions: BuildOptions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, that nobody has noticed yet that build-webpack and build-webpack-watch tasks uses the options interface from serve command. 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like one of those things that slipped :/

@filipesilva
Copy link
Contributor

  1. You're absolutely right, this still needs to happen. Maybe you can just replace the updateBaseHref function with a add404Page function, that just copies index.html to 404.html in the same position in the pipeline.
  2. Hm... I don't think so. The case where you manually change the baseUrl for a GitHub deploy is when you have it on a custom domain or something. We can't know what the custom domain is atm, so might as well leave this bit as is.

@filipesilva
Copy link
Contributor

Just noticed that had already done what I suggested via the createNotFoundPage function, cheers!

@filipesilva
Copy link
Contributor

Reviewed and flagged it as LGTM. It will be merged soon to be on the next release.

Thank you so much for this feature!

@dzonatan
Copy link
Contributor Author

Cool! But I see new conflicts.. again. 😄 Do I need to solve them?

@filipesilva
Copy link
Contributor

They're probably lint related, since I a big linting PR just got pushed. If you can look at them I'd appreciate it, but I expect it to be minor stuff as far as your PR is concerned.

Implement --base-href argument for build and github-pages:deploy commands

Closes angular#1064
@dzonatan dzonatan force-pushed the webpack-feature-basehref branch 2 times, most recently from 49df2da to 1e1ef93 Compare August 25, 2016 21:50
Reuse basehref handling logic from webpack build task
@dzonatan dzonatan force-pushed the webpack-feature-basehref branch from 1e1ef93 to f94a022 Compare August 25, 2016 21:52
@dzonatan
Copy link
Contributor Author

Forgot to notify that I rebased it yesterday.

@filipesilva
Copy link
Contributor

It's in! Thanks @dzonatan for all the work you put in this functionality, you should be able to use it in the next webpack release :D

@dzonatan dzonatan deleted the webpack-feature-basehref branch September 12, 2016 09:50
@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 10, 2019
clydin pushed a commit to clydin/angular-cli that referenced this pull request Aug 29, 2023
With this change we add hybrid rendering support in common engine, express engine and hapi engine.

Users don't need to do any changes to take advantage of this change.

The engine will serve the static prerendered page if a index.html exists for the given route, otherwise it will fallback to render the page in SSR.

Closes angular#1506
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request : ng build to include a --base-href <base>
4 participants