-
Notifications
You must be signed in to change notification settings - Fork 12k
Add --deploy-url
to application
builder
#26411
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
Comments
We continued using Angular as our frontend because of this promise. Due to having a MVC Razor base page with important functionality for our site, we have used the technique of injecting our index.html into a razor page. This means that our .js and .css files are not hosted at the same URL as the base page. We have had some success with manually adding the URLs of the .js and .css files to our page, but this technique does not work with lazy loaded modules. I would imagine users that host their files on a CDN would have similar issues. |
Had some discussion on this today. Our general stance is that We've been hesitant to add If moving off Separately, if you have a specific use case which requires |
--deploy-url
to application
builder
Hi, if it's discouraged... Can the docs be updated? https://angular.io/guide/deployment On the footer says Last reviewed on Mon Feb 28 2022 So perhaps new users need to understand why it doesn't work |
I'm creating a simple flask application, and don't want to manage the frontend assets with an external server. Without setting
Unfortunately, when defining this, the static_route overrides the catch_all that serves the index.html. When navigating to a frontend route, the server logically returns a 404 (it tried to find an asset file for that route and failed). The hack by setting baseHref="/static" and APP_BASE_HREF="/" would work, but breaks all CTRL-click, which is 100% not acceptable (I mean, it's a dealbreaker, the kind that leads to migrate to another framework). The only solution I found is to build using the
I get a warning that |
https://angular.io/guide/deployment#the-deploy-url states:
https://angular.dev/tools/cli/deployment#--deploy-url also discourages it.
What Ctrl+click behavior are your referring to? Do you mean ctrl+clicking a link where the browser opens it in a new tab? I don't see how
I'm not familiar with Flask specifically, but if I'm understanding your comment correctly it seems like it is not feasible to configure the server to both serve a static directory and also fallback to |
My use case - I deploy my front-end to an app server, but then a CDN pull zone caches static assets and serves from the CDN. eg My app is at domain.com |
We use angular/elements for building microfrontends with angular which each are hosted under a |
They are different things. separate them. |
@dgp1130 The ctrl+click would be broken when we use a relative link. Say we serve a site on Of course we could use javascript to intercept these cases and build an absolute url for use, but it's cumbersome and not intuitive. SDKs with business logic that are shared among sites built on different web frameworks would have to take it into account if we want to adopt them in Angular apps. There are also scenarios without javascript like SSR (used by crawler and SEO). It seems the reasons to deprecate |
@Mensu That sounds like the typical behavior of If you can create a minimal reproduction of a scenario where click and ctrl+click behavior are different, then I would be very interested to see it. |
Our use case is that we host two versions of our site on one domain as we are slowly migrating to Angular. |
@dgp1130 In fact the url opened by normal click is the same as ctrl+click, and I agree that's the typical behavior of |
My application is served in mydomain.com, and the CSS and Javascript chunks are served from the Cloudfront CDN for performance reasons. Removing Deploy Url prevents this extremely common use case. I think this option should be added back, as the removal was preventing us from upgrading to the new Angular 17 esbuild-based application builder, and our use case is extremely common. So it must be affecting a lot of people. Here is the script that I added to my build pipeline to add the CDN url manually to the bundles. This allowed me to use the EsBuild build in production: console.log(`Running apply-cdn-url.js...`);
const fs = require('fs');
const cheerio = require('cheerio');
// Load the HTML content
const htmlContent = fs.readFileSync('dist/browser/index.html.original', 'utf8');
const $ = cheerio.load(htmlContent);
// CDN prefix to be appended
const cdnPrefix = process.argv[2];
console.log(`Applying CDN URL: ${cdnPrefix} to the HTML file...`);
// Locate and modify script and CSS tags
$('script[src], link[rel="stylesheet"]').each(function () {
let tagName = $(this).get(0).tagName;
if (tagName === 'script') {
let src = $(this).attr('src');
if (!src?.startsWith('http')) {
$(this).attr('src', cdnPrefix + src);
}
}
else if (tagName === 'link') {
let href = $(this).attr('href');
if (!href?.startsWith('http')) {
$(this).attr('href', cdnPrefix + href);
}
}
});
// Output or save the modified HTML
const modifiedHtml = $.html();
const outputPath = 'dist/browser/index.html';
console.log(`Saving modified HTML to ${outputPath}...`);
fs.writeFileSync(outputPath, modifiedHtml);
|
We use a business scenario when we replace the history of pages via window.history.pushState. |
We also serve our application from one domain, and our CSS and javascript from cloudfront for performance purposes. I'd really like to upgrade to the To be clear, at least as far as I can tell, our use case requires |
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
This use case should be possible with the combination of the
or the following if the app is located on a subpath:
If the application is not using the Angular router than the If you encounter further issues with this setup, please open a separate issue with a minimal reproduction if possible. |
While the HTML base HREF does affect most relative requests it does not affect all. However, while ctrl+click behavior with relative links may be a concern for some applications, some others may not have an issue. The aforementioned suggestion may provide a solution to some that does not require the use of a heavyweight solution such as deploy URL which hard codes a specific path throughout the entire application in numerous locations. This not only makes the application non-transportable but also does not fully cover all file reference usages ( |
thanks for your effort and patience :) The base-href purpose is different in W3C specification and in angular "recommended" way. https://github.com/TheTomasJ/angular-router-example |
Thanks for that clear explanation. I hadn't previously understood exactly how we were intended to replace Unfortunately, If I do what you suggest, it causes a couple of issues, most notably, that all of the relative links on the websites (that directly assign the href with In addition, other resources we load on the page via relative links (such as additional js files) also now improperly point to the CDN (which really only hosts the files deployed for Angular). Essentially, the only requests that should go to the CDN are those for files generated by the Additionally, API requests to our back end which have relative URLS are also going to the CDN. This part I suppose I could fix with an interceptor, if the rest worked, but overriding the entire What seems like the right approach is I suppose I could open an issue for this, but it feels like it would just be a duplicate. |
Based on what you have described, what would the |
The Angular CLI is generating our I don't think a manifest of file build outputs would be more useful, at least for our use case. A more extensive As an aside, |
We have a different use case. Perhaps it's too edge case to consider for the new deployUrl option, but I'll share just in case a native solution can cover our needs as well. We do what many called out and have our app files hosted on a CDN domain (unique per environment) that differs from the domain serving the application to the user. However, we also do not use the CLI generated index.html file. We pull the generated resource tags (CSS, Script, and component tag) and inject them into an index.html file managed and hosted by our CMS. To get all this working without using the currently deprecated deployUrl option requires us to:
We haven't yet looked at moving to ng17 as we're waiting for angular-builders to add support for esbuild, but if we could simplify all of this with a deployUrl option and/or index templates, that'd be great. |
In my use case, there is micro frontend (angular element) that used as hostile component or remote app in none angular host apps and all resource files are not the same host app assets path. To deprecate this |
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
…uilder This commit adds the deployUrl option ot the application builder. Closes angular#26411
Thanks to the team for adding this feature to the application builder! Definitely appreciated! |
Thank you very much for supporting and keeping this |
Hi @alan-agius4, |
@tclyit, it will be available in 17.3 which will be released as the latest version later on today. |
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. |
I am referencing following response from @dgp1130, where is stated that "team does not expect that any existing use cases to suddenly become unsupported". From v17 there is no possibility to reference static assets with absolute url. Using base hrefs is not proper replacement because relative links must stay relative to root when users wants to open links in new tab (ctrl + click) and also for non javascript consumers of server side rendered pages. Combinations with APP_BASE_HREF are not applicable for this use case. Due to this we believe this is regression for no good reason.
Originally posted by @dgp1130 in #22113 (comment)
Updated 23.2.2024 with minimal reproduction:
https://github.com/TheTomasJ/angular-router-example
The text was updated successfully, but these errors were encountered: