Skip to content

add support for publicPath option in webpack #3136

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

Closed
wants to merge 4 commits into from

Conversation

Mischi
Copy link

@Mischi Mischi commented Nov 14, 2016

Hi all,

this PR tries to add the publicPath option for webpack.
I have not figured out how to test this feature yet? Would be happy for any suggestions though 😃

Personally i would like to use this feature to easily integrate angular-cli based projects into ASP.NET MVC applications but there are many other valid use cases for publicPath option. See BROCKHAUS-AG/AspNetAngular2IntegrationDemo for a simple demo ...

This should also fix #2276.

Cheers,
Fabian

@clydin
Copy link
Member

clydin commented Nov 14, 2016

Changing the base href doesn't do what you need?

@Mischi
Copy link
Author

Mischi commented Nov 14, 2016

Hi,

using base href works kind of. The problem with using base href is that it will also affect ajax calls which in my case is not what i want ...

@clydin
Copy link
Member

clydin commented Nov 15, 2016

You can either use root relative urls or provide an app wide config object with an api base url which can be prefixed to all ajax calls (good practice anyway in case the static content is split from the API in the future).

The nice thing about setting the base href is that it handles index.html, webpack, and angular routing all in one place.

@Mischi
Copy link
Author

Mischi commented Nov 15, 2016

You can either use root relative urls or provide an app wide config object with an api base url which can be prefixed to all ajax calls (good practice anyway in case the static content is split from the API in the future).

Yes, that works. Thanks!

But it doesn't feel correct to me though since my index.html is served on http://localhost:8080/ and all assets are below http://localhost:8080/Content/. Using base href would feel more correct if my index.html would be served from http://localhost:8080/Content/ too. But maybe that's just my lack of understanding as it seems to work with base href ....

Btw, my application structure looks like this:

  • ClientApp (angular-cli project)
    • angular-cli.json
  • Controllers
    • HomeController (serves ../Content/index.html on http://localhost:8080/)
  • Content (outDir)
    • index.html
    • main.bundle.js
    • ...

@Mischi
Copy link
Author

Mischi commented Nov 15, 2016

After playing a little bit more with --base-href i am pretty sure that --base-href is NOT what i want in my case.

I prepared two demos which demonstrate the difference between --basic-href and publicPath as i propose in this PR.

The --basic-href demo (http://ngcli-basehref.azurewebsites.net/) will use the --base-href "/Content" for routing too as you noticed which is not what i want.

If you compare this with the publicPath demo (http://ngcli-publicpath.azurewebsites.net/) you will notice, that /Content is only used for assets and not for routing.

@clydin, do you know a way i can archive this without publicPath?

Thanks in advance,
Fabian

@clydin
Copy link
Member

clydin commented Nov 16, 2016

Add this to your app module:

providers: [{provide: APP_BASE_HREF, useValue: '/'}]

As to the PR, I think that two options that perform similar functions but with slightly different outcomes could lead to confusion. Some guides on different hosting strategies would probably be useful regardless.

@Mischi
Copy link
Author

Mischi commented Nov 16, 2016

Thanks again!

@Mischi Mischi closed this Nov 16, 2016
@jbellmann
Copy link

@Mischi
Why did you close this PR? You don't want it merged anymore? I have seen lots of issues about this "publicPath"-config option.

@Mischi
Copy link
Author

Mischi commented Nov 18, 2016

Hi @jbellmann, the solution @clydin proposed works for my current project but if you care i can reopen it.

@Mischi Mischi reopened this Nov 18, 2016
@andyg3
Copy link
Contributor

andyg3 commented Nov 18, 2016

The solution from @clydin doesn't work in my case. I definitely need publicPath supported.

@jbellmann
Copy link

@Mischi

please notice my PR into your feature-branch. Contains only the missing test.

@clydin
Copy link
Member

clydin commented Nov 18, 2016

@andyg3 feel free to open an issue to discuss your use case

jbellmann and others added 2 commits November 19, 2016 12:45
# Conflicts:
#	packages/angular-cli/models/webpack-build-common.ts
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@Mischi Mischi force-pushed the feat-webpack-publicPath branch from 130d5c4 to 87b0b3e Compare November 19, 2016 12:03
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@jbellmann
Copy link

@here I signed the CLA, but somehow the @googlebot is not checking again.

@andyg3
Copy link
Contributor

andyg3 commented Nov 21, 2016

Is there a way to kick the @googlebot into re-checking this?

@changLiuUNSW
Copy link
Contributor

changLiuUNSW commented Nov 24, 2016

Is there any update with this? I really need publicPath support.

@jbellmann
Copy link

@Mischi

I merged latest changes from master and created a PR for your feature-branch.

Is there an easier way to handle this?

Regards,
Jörg

@rsnj
Copy link

rsnj commented Nov 24, 2016

I really need publicPath support as well. Will be great to get this merged in.

@changLiuUNSW
Copy link
Contributor

changLiuUNSW commented Nov 25, 2016

I think this one can be closed
Another PR created including command line support and unit test
#3285

@filipesilva
Copy link
Contributor

Superseded by #3285, as it is more complete.

@filipesilva filipesilva closed this Dec 8, 2016
hansl pushed a commit that referenced this pull request Dec 29, 2016
…3285)

Add publicPath option for webpack.

User can specify publicPath via `--deploy-url` / `-d` from command line or add `deployUrl` to `angular-cli.json`.

It can solve following issues:

Change the public URL address of the output files (different from baseUrl).
Manipulate the request url for chunk js files.
It is very helpful to solve resources url and route lazying load issues for those applications which have different static files paths such as ASP.NET MVC.

Fixes #3136
Fixes #2960
Fixes #2276
Fixes #2241
Fixes #3344
MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this pull request Feb 9, 2017
…ngular#3285)

Add publicPath option for webpack.

User can specify publicPath via `--deploy-url` / `-d` from command line or add `deployUrl` to `angular-cli.json`.

It can solve following issues:

Change the public URL address of the output files (different from baseUrl).
Manipulate the request url for chunk js files.
It is very helpful to solve resources url and route lazying load issues for those applications which have different static files paths such as ASP.NET MVC.

Fixes angular#3136
Fixes angular#2960
Fixes angular#2276
Fixes angular#2241
Fixes angular#3344
@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 11, 2019
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.

No publicPath option in configuration file
8 participants