Skip to content
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

Flatten glob "assets" to one output folder #14158

Open
Nkmol opened this issue Apr 14, 2019 · 11 comments
Open

Flatten glob "assets" to one output folder #14158

Nkmol opened this issue Apr 14, 2019 · 11 comments
Labels
area: @angular-devkit/build-angular feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature
Milestone

Comments

@Nkmol
Copy link

Nkmol commented Apr 14, 2019

🚀 Feature request

- [ ] new
- [x] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

I am currently working with nested assets folder per entity map. Currently, I am using the following assets export settings:

              {
                "glob": "**/assets/**/*",
                "input": "src/app",
                "output": "/assets",
                "ignore": ["**/*.ts"]
              }

Imagine having the following file structure:

src
├── app
|   ├── module-folder
|   |   ├── assets
|   |   │   ├── images
|   |   │   │   └── image1.png
|   ├──other-module-folder
|   |   ├── assets
|   |   │   ├── images
|   |   │   │   └── image2.png

What I get

This would result in the following dist/ file structure:

dir
├── assets
|   ├── module-folder
|   |   ├── assets
|   |   │   ├── images
|   |   │   │   └── image1.png
|   ├──other-module-folder
|   |   ├── assets
|   |   │   ├── images
|   |   │   │   └── image2.png

What I want to have

dir
├── assets
|   ├── image1.png
|   └── image2.png

What I have tried

I have tried to use a custom script to move the assets files manually in a flatten way to the dir folder.

for file in ./src/app/**/assets/**/*.*; do cp "$file" "./dist/assets/$(basename -- "$file")" ;done

This, however, does not work in combination with ng serve as the files are in-memory, and also does not work with the ng build --watch as I am unsure how to activate script after it has been built.


I would love to get some insight into the best approach. Maybe this is simply using an already existing flow. From my point of view, this should be included as functionality, as the nested folder structure strategy seems to be one of the more common approaches.

@alan-agius4 alan-agius4 added area: @angular-devkit/build-angular feature Issue that requests a new feature labels Apr 15, 2019
@ngbot ngbot bot added this to the Backlog milestone Apr 15, 2019
@alan-agius4
Copy link
Collaborator

Hi, thanks for reporting this.

Thinking about this more flattening the assets output is dangerous as this might cause file collisions since non of the assets files gets fingerprinted and a file with the same name can exist in a different nested folder.

@xoneill
Copy link

xoneill commented May 8, 2019

It would be nice to add this as an option, similar to CopyWebpackPlugin

@mario-d-s
Copy link

@alan-agius4 You're right that file collisions can be an issue but printing a warning to the console on build might be enough. In the end it's the developer's responsibility; if we are specifying we want all files in one folder, we couldn't have duplicate file names even if we were using any other build tool.

@Eraldo
Copy link

Eraldo commented Nov 24, 2019

Django (python web framework) also does this and takes care of the collision via teaching the users a naming convention.

E.g.:

module1/assets/module1/images/image1.jpg
module2/assets/module2/images/image1.jpg

By adding a subfolder with the same name as the nested module, there should be no collisions.
In case of doubt it uses the first one it found. (Could also be the last one in case of glob)

I also would prefer using module local assets for some modules. It matches the whole lazy loading isolated module structure idea, is what I think.

@suiyun39
Copy link

The problem is that so far the cli cannot handle references to src in html.
Some very common requirements, such as: hash filename, add cdn host. cannot be implemented

@suiyun39
Copy link

I think cli should learn vue cli in this regard. If the file is in a specific folder, only copy it.
If the file is referenced by html or css, use webpack loader to convert it to require. next to other loader.

@suiyun39
Copy link

I have observed that html references are not processed at all, I think this is a design error

@Iworb
Copy link

Iworb commented Nov 22, 2021

Any updates on this feature?

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 1, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@ngbot ngbot bot modified the milestones: Backlog, needsTriage Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 21, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Feb 21, 2022
@sod
Copy link

sod commented May 14, 2024

fun fact, the new vite/esbuild based build does exactly this. One side effect is though: If you have two files with the same name in different folders, you get a build error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular-devkit/build-angular feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

8 participants