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
How to set 'publicPath' in webpack after 'deployUrl' option is deprecated in version 15 #22113
Comments
|
That's also an issue for us. We have a widgets application that contains multiples lazy loaded custom elements. These elements are used in other applications. When some element want to load an image it should be loaded from the widgets domain, not from the current one that belongs to main application. Currently this can be achieved by using deploy-url during widgets app build. How to do it without this option? |
|
@feng-xiao, can you please elaborate on why you need the deployUrl option and the specific use-case? @artaommahe, is the image located in component stylesheet or external stylesheet? |
|
@alan-agius4 in component's scss files |
|
@artaommahe, in that case there is no alternate option for that. One thing to point out is that this aligns the behaviour of images defined in HTML and CSS, which results in images URI HTML to always be relative to HTML. What comes to mind is to have an external CSS file (styles.css) that you defined the image in, since images are loaded relative to the stylesheet origin. Though this might be a bit cumbersome. |
|
@alan-agius4 using global css file breaks lazy loading of such stuff, locality of code (images of some component from one of the widgets lib somehow are placed in global styles file). |
|
If the assets can be referenced from the component templates instead, another option is to generate the full asset URL at runtime via the use of |
Hi @alan-agius4 , I've integrated Angular app into an ASP.NET MVC application, i.e. the Angular app is initialized by a MVC razor view. Since the Angular resources are generated and hosted in different port number in 'ng serve' mode than MVC app, e.g. ASP.NET MVC app is loaded in localhost:8444, Angular app would be loaded in different port number like localhost:8445, I need to make Angular resources loaded using absolute URL, otherwise, they'll be loaded in wrong URL, the one MVC is using (i.e. localhost:8444). |
Hi @alan-agius4 , based on webpack's source code, I don't see any overhead by setting 'publicPath' to webpack config. I don't know why Angular Doc says it could increase build time. |
|
@feng-xiao, the Another disadvantage of using In your cases, the recommended approach would be to use a combination of both Razor View ...
<base href="http://localhost:8445/">
...app.module.ts ...
{ provide: APP_BASE_HREF, useValue: 'http://localhost:8444' }
... |
|
@alan-agius4 We heavily use too the deployUrl parameter. For us, it's because we have a reverse proxy that route all requests under With the deployUrl we currently have <!DOCTYPE html><html lang="fr">
<head>
<base href="/context/path/">
<meta charset="utf-8">
<title>My application...</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="static/favicon.png">
<link rel="stylesheet" href="static/styles.8277a10e7c2be6c58f14.css" media="print" onload="this.media='all'">
</head>
<body>
<app-root>loading...</app-root>
<script src="static/runtime-es2017.5a110097badef840dfda.js" type="module" crossorigin="use-credentials"></script>
<script src="static/runtime-es5.5a110097badef840dfda.js" nomodule defer></script>
<script src="static/polyfills-es5.1f50460b6153455d79c6.js" nomodule defer></script>
<script src="static/polyfills-es2017.acf5917270495d93417a.js" type="module" crossorigin="use-credentials"></script>
<script src="static/main-es2017.f3526c48e4006bc6f2e3.js" type="module" crossorigin="use-credentials"></script>
<script src="static/main-es5.f3526c48e4006bc6f2e3.js" nomodule defer></script>
</body>
</html>If this parameter is removed, we're just screwed :/ Also, the TLDR : we'd love to keep the option to have both base-href and deployUrl (or whatever it's named) configurable. A full example project is here : https://github.com/mpalourdio/SpringBootAngularHTML5 |
|
Our dev build relies on |
|
Same for me , in asp.net loaded from index.cshtml like mpalourdio... would break everything... |
|
I have mentioned my use-case in #22208 Currently I am using the following option for building the application, In my case, static assets needs to be load from /portal/public/<asset_path> where as routing or http request needs to fire with base-href which is /portal/. In our case, we are doing white-listing the security for the path having public in it as it has only static assets. What would be your recommendation in this case? I tried with steps mentioned in #22208 (comment) but the issue didnt got resolved. Please see #22208 (comment) |
|
deprecation of Note: In my case, i am using relative path |
|
Can someone explain how I can avoid having all the garbage ("main.js", "runtime.js") etc in the root folder with base href="/" when deployUrl is removed? I don't want to write a script that rewrites urls. I just want to run "ng build --watch" and get the correct result from an already running webserver when I change files. I get this with --base-url="/" and --deploy-url="/app". (I don't have performance issues, so… why create problems for no good reason?) |
|
@alan-agius4 similar case as above - we're adopting module federation for some of our projects to split huge apps into smaller pieces to reduce development and deployment time cost. We have to use |
|
Curious, what's the Angular Team's argument for removing |
|
@alan-agius4 Is there any hope of Angular reverting the change to |
|
@Blackbaud-SteveBrush, in your case you can set the However, this issue is related to removed What is your use-case of using this option? |
|
We have a custom The URL above (i.e. If there's an alternative way to generate a dynamic |
|
We have a similar case where we define Setting the @alan-agius4 - Once |
|
We have a similar problem without deployUrl. We have had ability to serve 2 different versions, Dev served from local files and Prod served from CDN. The HTML would load files based on |
|
As a work around for the WebPack If you have different build configurations you can store the appropriate value in the I do want to upvote this question though because it is a breaking change without any angular specific work around. We also use asp.net mvc to host the root file (instead of the angular index.html file) so the angular distribution folder is no the same as the load point url that asp.net uses. This means that anything dynamically loaded with |
|
I'll add my 2 cents: we don't use Angular-generated Now angular team suggests to use a combination of
export class IgnoreBaseHrefInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if (request.url.startsWith('/')) {
request = request.clone({
url: `${location.origin}${request.url}`,
});
}
return next.handle(request);
}
}
Frankly speaking, all this looks like a very doubtful alternative to a simple |
|
After reading the comment of @alan-agius4 again. He said following.
How many people here that need To be clear, I host all the assets directly on CDN, not within the repository to be deployed through assets. So, for my scenario,
So, alternative approach is to introduce another parameter to allow deploy URL only for JS, CSS and templates, ignore assets. That way, Angular CLI does not have to process anything related to assets, nor it will have much burden of package size. |
|
@th0r expanded what @alan-agius4 have suggest to use I would try to provide few solution as well, some of them require angular team's implementation, which I will list here as potential get around.
That's all the solutions I can think of. First two solution depends on Angular team, where last 2 require backend skill. Which is what I am familiar with. Add @th0r's solution on top of it. Which is five different ways. So, if Angular team removed without introduce alternative way such as 1st and 2nd solution, we have at least one front end solution and two back-end solution. |
|
This will cause us a lot of discomfort as we rely on We set the value as Coming up with alternatives to this will be complex and will involve some tradeoffs (be it writing a script for the |
@IgorWolbers didn't work for me though. // main.ts
declare var __webpack_public_path__: string;
if (environment.production) {
__webpack_public_path__ = 'https://some-cdn.com/';
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));after running |
|
@aashwath - that is expected as this is for runtime behavior not for build time behavior (generation of the index.html file). If your |
|
I suggest angular official dev team to keep |
|
I really don't see why this was forced on the build. Listen guys, not everyone hosts the Angular way. There's nothing wrong with keeping the deployUrl option for those of us who need it. It doesn't play well with ng serve but that's fine, I just don't use ng serve. Don't make me hardcode the deployUrl all over the place to get this thing functional again. |
|
I'll add to the list of replies, please don't deprecate/remove this option. Our application run from a .Net MVC razr view with assets hosted elsewhere, so the baseHref for routing is separate from what deployUrl does. You should assume having the base html page / routing / api calls independent from the assets loading calls is a pretty common use case, and module federation might become a pretty common one too. |
|
I also need the deployUrl for AWS CDN of assets and baseHref to do the routing (i have a fun naming: https://myurl.com/with/team/avengers) ... so the app is hosted on "/with", and use "baseHref": "/with/" in production. My assets are not on "/with" .. but on "https://cdn.myurl.com/" |
I'm on Version 13 same problem here: 'test' was not added to the build html paths |
|
It seems that so many use cases are in favor of keeping the deployUrl option. I don't know if it would be possible for the Angular team , to enable/disable to use of deployUrl in configuration so that developpers who want it can opt-in for build performance gains and developpers who need the current behavior can keep using it ? |
|
@alan-agius4 Any hope? |
|
I also need deploy URL, otherwise the chunks are not loaded correctly. |
|
This causes problems with our setup too. We use Spring Boot to serve the Angular app. The app is being built under E.g. suppose the server runs on With the deprecation of deployUrl we need to set the base href to Obviously there are ways around it (the best one currently being using deployUrl while we still can), but I would like to know what an elegant solution to this problem could be. |
|
We also have problems with the deprecation of Our server serves two Angular applications from the same path depending on whether the user is authenticated or not, with the help of
Any idea how this can be handled without |
|
How to use I'm closing this issue for now as we don't see anything directly actionable here, but hopefully better documentation and a future blog post will help clarify how best to meet your requirements. |
|
@dgp1130 Could you clearly describe what will happen to People who posted here, or at least for me need an clear path of whether |
|
We are still planning to remove |
|
Had this same issue but found a solution that worked for me - https://stackoverflow.com/questions/71695674/what-is-best-way-to-go-about-replacing-deployurl-in-angular-json-for-v13/71913980#71913980 |
did you ever managed to work things out with omit deployUrl and using APP_BASE_HREF? |
|
@benjaminadrom tey a solution posted by @ThomasDevens above. It worked for me. |
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |


angular-cli/packages/angular_devkit/build_angular/src/webpack/configs/common.ts
Line 335 in 5402f99
The text was updated successfully, but these errors were encountered: