Skip to content

path in index #2568

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
erhard opened this issue Oct 7, 2016 · 7 comments
Closed

path in index #2568

erhard opened this issue Oct 7, 2016 · 7 comments

Comments

@erhard
Copy link

erhard commented Oct 7, 2016

OS?

all OSes

Versions.

1.0.0 beta 16

If you programm the angular app as part of another app for example Rails application the path of the css file and the javascriptfile is relativ to the public dir. If you put the angular part in for example public/ang the js and css file should have the path "ang/main.js in the index.html to load the javascripts and css.

Example 👍

the generated (ng build --prod) and modified index.html

<script type="text/javascript" src="apollo/ang/inline.js"></script><script type="text/javascript" src="apollo/ang/styles.e87a73ae6c0622a05f75.bundle.js"></script><script type="text/javascript" src="apollo/ang/main.99efe10dac980567b9ae.bundle.js"></script></body>
</html>

this should be done via ng build --path "apollo/ang"

This feature would be very helpful to integrate angular2 with angular-cli in other application

@fullstackdave
Copy link

fullstackdave commented Oct 7, 2016

Agreed, JS source files and the resulting HTML needs to have separate destination directories, and a simple HTML file with ONLY the resource script definitions would be very helpful.

@arlowhite
Copy link

You can set base href with ng build --base-href, but I agree more flexibility is needed.

If you try to use base href to load these files from another directory, it will work, but also impact other URLs in your app.

For example, say you want these files under /assets/ so you set --base-href=/assets/

This will work, but other relative URLs will be impacted.
http.get('api/foo') will GET /assets/api/foo

So angular-cli really needs something like a outResourcesUrlPrefix option.

@clydin
Copy link
Member

clydin commented Oct 8, 2016

@arlowhite, If you didn't want your http.get to be impacted, why would you use a relative URL? The whole point of a relative URL is that it can be impacted by its context. Serving the output from a subpath would also cause the GET request to be altered.

Changing the base href is really the way to go; lazy-loaded routes, image tags in templates, url()'s from inline CSS, etc. should all keep working as if the index.html was in its original location.

@arlowhite
Copy link

My point was that in this scenario, you do want base href to impact your API URLs. Maybe you deploy under / sometimes, and /my-app/ other times and the angular-cli app is deployed alongside some service.

Of course you could just prefix all your API URLs with some configurable variable. There are a lot of ways the developer can deal with the problem. But if angular-cli provided a resourceUrlPrefix option in addition to baseHref, it would be convenient for developers that use relative URLs in their app and also want to relocate the webpack resources to be served from another path.

@clydin
Copy link
Member

clydin commented Oct 9, 2016

@arlowhite, my apologies. From the comment it seemed like you were just using the relative URL because it was quick and easy and happened to work. I would still caution against the approach, it's a little magical and a new developer taking over the project could very easily break things. And if the base href ever needed to be changed, there's going to be a large amount of find/replace.

As a general pattern, I'd recommend an app config service containing app-wide settings that can be injected where needed. One of those can be the base API server URL. If needed this URL could even be computed at startup from document.location.

@filipesilva
Copy link
Contributor

Dupe of #2276 I think. If that's not the case, let me know and I'll reopen.

@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 6, 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

No branches or pull requests

5 participants