-
Notifications
You must be signed in to change notification settings - Fork 12k
add optional "input" and "output" paths to "index" in angular-cli.json #7309
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
I'm thinking that this is more of a bug really. I think the index.html should always be in the root directory and not copied across with it's directory structure, since JS is forced into the root as well. Other HTML files can be copied across as assets and would maintain their folder structure depending on where they are |
I have similar requirement, but with slight difference... I am not able to find any solutions and neither I was able to find any tickets around for that. If there is one then I am really sorry but please redirect me. |
@out-of-memory Maybe this can help you? Also, you don't explain why you would like something like that to happen. I think your request is different than this issue. |
Found the culprit: https://github.com/angular/angular-cli/blob/master/packages/@angular/cli/models/webpack-configs/browser.ts#L67 If that's hardcoded to index.html then we get the solution that we're after:
Any thoughts about having a second property for outputIndex or flattening that second property @filipesilva before someone makes a PR? Desired functionality.To have the index.html reside in the same folder as scripts, which cannot be output anywhere else currently The following would work I think: appConfig.index.substr(appConfig.index.lastIndexOf('/') + 1); |
The reason you end up with dist/dm/dm/index.html is because you have dm in both index and outDir. Change index to index.html, root to src/dm and outDir to dist/dm. See #7124 where I posted a more in depth response about this. |
@grizzm0 Yes "dm" is both in index and outDir. I was forced to cause of an issue which is not solved yet. Also, could you confirm if the solution you suggest can be built with AOT and works when an app loads a lazy loaded module from "shared code"? It would be great if "input" and "output" optional paths were added to "index". It does not harm anyone and index.html is not forced to have the same path (from root folder) in production and development. |
I feel like the index.html should always be at root, so it's on the same level as the scripts it needs to load which are always at root. I've almost got the |
I've added an example using a different root property amongst a few other things like SCSS Vars and Image replacement: https://github.com/intellix/angular-cli-library Thanks to @nekkon and @grizzm0 it serves, builds and can be tested. IDE is reporting that |
@intellix Your example does not work with AOT. Also you do not lazy load the shared module which is a common scenario. Add --prod flag to your build commands and see what I am talking about. |
@grizzm0 @intellix I have created a new branch with an example of a lazy loaded module of the shared code. It follows your suggestions/solution. ng serve works, ng build works but ng build --prod does not. There are open issues with angular-cli that do not allow your suggestion/solution/examples to work. That is why I created the repo angular-cli-library. In that repo AOT works with/without lazy loaded modules, which is something important if you want your app to be built for production. The only problem is that index.html ends up in "app-name/index.html" instead of the outDir folder. That is why I created this issue. Until this is solved, if you copy/transfer index.html to the parent folder everything works properly. This is why I ask for the functionality @marcincichocki requested #7124. |
It's part of an overall philosophy we follow that relative paths should always be maintained. |
@filipesilva The functionality I request exists "input is relative to the project root (src/ default), while output is relative to outDir (dist default)." Relative paths are not maintained with |
It does exist for assets, yes. Mostly to support copying stuff from node_modules though, which is necessarily outside the source directory. Is there something that prevents you from moving |
@filipesilva This whole issue is about multiple apps more or less. I've suggested to change the root to src/dm and keep index as index.html. This is related to what you and @intellix discussed on slack earlier today with the AOT issue. |
@filipesilva Yes I can not move one directory up. I can not use @grizzm0 's suggestion as AOT does not work with modules that are lazily loaded outside the project. I do understand that under normal conditions @grizzm0 's suggestion is the way to go, but there are open issues (ex #5986 ) that prevent his solution to work 100% at the moment. That's why I asked to add the optional paths (input/output). @grizzm0 You have been insisting the last two days to use your solution. You also say that a shared library of components can be used with it. Have you tested the example which @intellix made based on your solution? I have repeatedly asked you to, so you would see that with what you suggest AOT does not work. By setting tsconfig the way I do, although it seems wrong, everything works fine for me (AOT+lazy loading of modules from a shared folder of modules/components). When all open issues are solved (something that will take time) I will change tsconfig to what @grizzm0 suggests. |
The PR I've created flattens the output location of index.html so that it always exists at the root of the application alongside the JS bundles. I still think this is correct as you can't request JS files like: Basically an index.html in another folder upwards will never work out of the box without #7314 One thing that does work for loading files from a Core location, is moving the SRC to a separate repository without a build-step and requiring them in via |
@intellix "you can't request JS files like: ../vendor.js" -> deployUrl can be used to do that. Just telling you so you know. I did it by setting "deployUrl": "./". That's why index.html works properly in the root folder in "dist/dm" although it is built in "dist/dm/dm". If I had set it to "../" it would had done what you say it can't. @intellix Your PR does solve the problem we have, but it could create problems/issues to users that want it to work otherwise. I would support you if that might not happen. That's why I asked for the optional paths for index as that wouldn't cause any problem/issues to anyone, but give more options to developers. I believe things should be flexible for each developer to have enough options that cover all possible scenarios. If you make things too strict, absolute and you miss usage scenarios, you disappoint them and make them feel that this was built only for a few people/companies and not for everyone. (as they can't change how angular-cli works by default.) |
@nekkon I've changed my example repository to look closer to yours, as that's working better for us at the moment as well. One thing that's not supported there though still is
On the note of having fake packages/libraries though. We tried the monorepos stuff but I believe we had the same issues to do with AOT from another place. I tried this: sparkles-dev/a-glimpse-at-yarn-workspaces#2 |
@intellix In my library repo CoreModule has no issues in being lazy loaded, as with any other module being lazy loaded from inside the "src" directory/subdirectory. From the error message above I think your problem is related to #7341. I have solved this issue (workaround) in my library. As I have previously said, my library repo is a result of many workarounds and except of this issue everything else works fine atm. It saves you time if you use something that works than continuously trying to solve problems/issues. |
I don't believe your repository has solved the same thing. Yours is doing:
The problem I'm having is that I already have a huge application and just need to decorate it with different SCSS variables and Images depending on the app served. This means I have something like:
It's essentially something outside of src not being able to lazy-load it's own stuff. |
@intellix 'shared' depends on a lazy-module from 'shared'. 'app1' imports 'SharedModule' You can also do that and it works. The only restriction is for all modules to be in the src folder (either in shared or in each app). If you want the files to be outside the src folder there is an issue open which does not allow you to. |
Has something been done to manage this in the end ? I have a multi app setup and my index output for (for example) "app2" is
Edit : In case someone is having the same problem I'll post how I solved this for now :
My
My output folder structure is now normal :
|
@Lakston That's a nice idea, but the opposite problem will then occur with the assets. Say the folder structure is like this:
And that the app config is
The output of the build will then be:
Since the assets folder was accessed using a relative path, it is also seems to be copied using the same relative path, in this case two levels above the intended dist output folder. We definitely need a flexible way to deal with this. |
I have since found a better way to handle my 4 apps, it required me to duplicate some files and folders (like my assets) but I am happy of how things are going now. I've read some commits and found out about the
I have duplicated quite a few files but now the benefit of this is that I can generate things via the CLI, the proper paths will be respected and the right app module will get updated like so : It will create the components in the right place and update I am in the process of making typescript aliases so I can avoid some But for now, this works ! |
@Lakston Hi, can you explain how appRoot is different than setting the root folder of the app? As I see from your example both apps have "." as the value. How does setting "." change things? Maybe this could solve the "index" issue. Thanks in advance and for pointing out this new option. Maybe @vsavkin can explain it to us or add it to the docs? |
I am confused by this too, from what I can gather it allows me to use the |
I would definitely like to do something like this in the app definition with index.
I have a second version of an app that requires a different index.html and at the moment the output keeps the alternative index name... |
@jpduckwo This is what I want too. I'm using Angular inside a PHP Laravel application and the front page will be served from the blade template |
Any news about it? I have multiple apps and I can't move to root dist folder for each app, because it is generated with relative paths inside index.html linking styles, main bundle.. |
@marticrespi since encountering this, NX CLI came out which was made for multiple apps. I've personally moved to there and would recommend others to as it has some good tooling for multiple apps: https://nrwl.io/nx |
@intellix we also using nrwl, but |
Still a "No."; eh? |
This is now supported in Angular CLI 8.2.0 or greater. |
Awesome. |
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. |
It would be great if "input" and "output" optional paths were added to "index" in angular-cli.json. There are scenarios that can not be covered with current implementation. (even using deployUrl)
With the current implementation the path of index.html after build is forced to be the same with the location during development. This is not always the case. An example is when folder structure in development is different than production. In such case the output path of the index.html can not be the same.
For example in angular-cli.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "orco-frontend"
},
"apps": [
{
"name": "dm",
"root": "src",
"outDir": "dist/dm",
"assets": [
{ "glob": "/*", "input": "dm/assets/", "output": "./assets/" },
{ "glob": "favicon.ico", "input": "dm/", "output": "./" },
{ "glob": "/*", "input": "shared/assets", "output": "./assets/" }
],
"index": "dm/index.html",
"deployUrl": "./",
In this example there is an app (dm) in src folder. The index.html file after build ends up in dist/dm/dm/index.html while it needs to be in dist/dm/index.html.
Even if you change outDir to the folder: "new location", index.html will still be built to the folder "new location"/dm/index.html. All the rest of the necessary files of the build will end up in the folder "new location" which is not the proper file/folder structure. This should not be forced to happen.
The text was updated successfully, but these errors were encountered: