-
Notifications
You must be signed in to change notification settings - Fork 12k
--deploy-url will have no effect on assets paths #4517
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
Hello! I am running into the same issues. I am deploying an app written by someone else. Components have hard-coded paths like /assets/img/etc (note the leading slash compared to the OP); the main application files (*.bundle.js and sourcemaps) end up in the root of the dist directory. This is okay for frontend development (using ng serve, /index.html can load /index.bundle.js and /assets/img/etc), but for the actual deployment I would ideally have everything under URLs looking like /static/app/ and /static/assets/ for example. Ideally, we would have set up different paths and directories from the start if we had thought about the server considerations. Trying to minimize changes at this stage, I found the one-line documentation for base-href and deploy-url not very enlightening, but PR #2276 seemed like deploy-url was intended to solve my issue. I am still experimenting in CI to see if that works for the main js files, but this ticket tells me it won’t help with the assets URLs. |
I had this problem too. All my resources are served on a subdomain. Using the deployUrl option solved the issue for the scripts/styles being loaded from the subdomain inside the index.html. This guaranteed me to not worry about base href so that my routing will work properly, it remains as default |
Facing the same issue here, I've got some CSS like this: label.custom-radio-default-label {
margin: 0;
clear: none;
cursor: pointer;
background: url(/assets/images/custom-radio-normal.svg) left center no-repeat;
background-size: 20px;
font-size: 16px;
font-weight: normal;
} and building with |
Largely fixed by #4803. The |
@filipesilva #5254 Here is a related issue that I've posted 3 days ago. Hope you will fix this soon. |
@filipesilva Does #4803 rewrite paths for assets that are images or javascript files, or only CSS files? |
The example in the original message is an image. The source code contains |
@merwok if you have Make sure you're using the latest RC though. |
Thank you for the reply! I’ll check with my team when we can upgrade and adapt our CI to benefit from the new behaviour. |
@filipesilva It affects urls stated in CSS files, but it doesn't those which are directly stated in markup like |
@milankr we do not process HTML, so that is expected behaviour. |
Ah! If only index.html is changed and not the other HTML files, I’ll have to keep my sed workaround. Next project, we’ll get the paths right from day one! |
@filipesilva can you tell me what the reasoning was to only process asset urls in css, and not in the html templates? |
@filipesilva What is the strategy using "The example in the original message is an image. The source code contains img src="assets/logo.png" (in my case, src="/assets/logo.png") but the files will be served from /static/assets/." The request for the image resource will 404. |
Is there any workaround to make this work for |
@bergben the only workaround that now reading the thread is to use Javascript binding so you configure the base path in your environment config files 👎 |
@filipesilva any updates on this? I need HTML processing as well |
FWIW, I lived with renaming |
I need to put Index.html in root directory i.e. /dist folder and all script files in dist/scripts directory, can anyone please guide how do I achieve this? So that when I deploy it on server my index file resides in root of my domain (mydomain/index.html) and all scripts in scripts directory (e.g. mydomain/scripts/****.js) |
@tomasklingen it was attempted a couple of times but at the time we couldn't find a safe approach for it, especially since you can compose urls in html using component variables. So any change there was very likely to break some projects, which is a breaking change and thus outside of 1.x. |
@filipesilva Can we get some sort of reserved string/variable/token that you can search in HTML and TS to replace all occurences? |
For those of us who are not in production yet. Should we think about some workaround or we can expect some fix in next releases(even not in 1.x)? |
When you deploy to prod, extract <base "/"> of the index.html, just this! |
I think there are two workarounds: either move your source files and do a mass search and replace so that the source paths match the deployed paths (what I mentioned in a previous comment), or use the ng eject command to get access to the raw webpack config and get out of ng cli. |
I have a work around in the mean time. I put the deploy path in my environment.ts files. Then in the components that I want to refer to files in the assets folder, I set href/src to "{{deploypath}}/assets/...". You will have to create a deploypath component variable and assign the environment.deployPath in the constructor of the component. |
@zsmorgan21 We do the same thing. When we deploy, we have a script that updates our package version and replace the value in our environment file. It works so far. |
I'll reference this StackOverflow post https://stackoverflow.com/questions/47885451 As I've ran into the same issue, The proper CDN support for any client-side apps framework is quite important; I'm not deep into Angular/CLI to know all the ins and outs to propose a solution, but it is something we're definitely running into when planning CDN deployments. |
Generally, setting the |
https://stackoverflow.com/questions/39287444/angular2-how-to-get-app-base-href-programatically |
Could you elaborate on why using the All relative fetches made by the browser will be prefixed by the provided base href. This would include all relative asset URLs within the application. This is also why it is generally a cleaner solution as opposed to the |
When you refer to `base-href`, are you referring to the command line
parameter or the base tag and href attribute? I think there is some
confusion there. Your initial post was missing the "--" from `base-href`.
Zachary S. Morgan
Hampden-Sydney College
Class of '14
…On Tue, Jan 23, 2018 at 3:19 PM, clydin ***@***.***> wrote:
Could you elaborate on why using the --base-href option will not solve
the asset issue?
All relative fetches made by the browser will be prefixed by the provided
base href. This would include all relative asset URLs within the
application. This is also why it is generally a cleaner solution as opposed
to the --deploy-url option which requires the supplied URL to be embedded
throughout the application to function. The APP_BASE_HREF token (which is
used as the Angular router base path) would generally be set / in this
scenario; as the default value is actually the base href of index.html.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4517 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGtzhNWpbDTiBrLJ0YGFdOXHLsMPv-ydks5tNj7TgaJpZM4L6mvx>
.
|
Reading all this, and it still doesn't explain how to have assets mapped to a CDN, even with using this This is the build command, which maps
So, the app is served off of a webserver host's subpath (so, Angular routing must work with this subpath, as the link I shared explains), but angular files are stored on the CDN. With the above build command, built JS/CSS files are correctly referenced with CDN URL in the What is needed is the way to Thank you |
The purpose of the @zappan Something similar to the following command:
with |
Can some one throw light on this, how to achieve context path other than / for my application. I had been reading whole night for this issue but could not find a way |
@zappan did it ever work for you? I tried without any luck and am stuck with it. Could you please assist? |
@ga-kumar wrote a script using |
thanks @zappan , I also ended up doing same.. Clydin's suggestion didn't work for me either or not sure if I understood correctly.. anyway.. thanks again.. |
Having the same issue. For now I am going to place a deployUrl to every src of html images. |
@albanx Use |
Hi, @clydin I have encountered the similar problem, Please help. Angular CLI: 6.2.5
Node: 8.12.0
OS: darwin x64 My deploy situation:My site have to be deployed on server A because of domain, so I put index.html ( generated file in way 1: Failed with some assets link in html did not converted to CDN path, so assets link in html breaksng build --prod --base-href /111/ --deploy-url https://B.com/111/ way 2: all the Angular router and http api both breaks, since all api and router are added with the base-hrefng build --prod --base-href https://B.com/111/ I have already set the @NgModule({
...
bootstrap: [AppComponent],
providers: [
{provide: APP_BASE_HREF, useValue: '/'}
]
}) Please help and let me know if you want more information. Thanks! |
Assets in ts file is has no impact on deployUrl. I was trying dynamic configuration https://christianlydemann.com/implementing-dynamic-environments-in-angular-for-avoiding-one-build-per-environment/
Can anyone help me how deployUrl can be used to update references ts file? |
Still we don't have any solution for the same issue. Don't know why this ticket is closed. I am building my application on cnd server and serving my index.html file from other domain which is my public domain. The build command for same is like My requirement will be fixed only when static content would served via deploy url. Note: All the chucks file are serving correctly via deploy url path on main/public domain. Only facing issue with static contents which are deployed inside "svg" and "assets" folders. Application is not working fine when I am trying to hard code cdn path of "assets" in |
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. |
Versions.
Repro steps.
img src="assets/logo.png"
in a templatecopy the content of the dist to "htdocs/mysubfolder" on any webserver or use
app.use('/mysubfolder', express.static(path.join(__dirname, angularDist)));
on a node server.The log given by the failure.
404 on all assets because it will ignore base href or deploy url and just use GET /assets/logo.png
Mention any other details that might be useful.
The text was updated successfully, but these errors were encountered: