Skip to content

Webpack skips images referenced in html templates (img src) #2231

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
alexsorokoletov opened this issue Sep 19, 2016 · 9 comments
Closed

Webpack skips images referenced in html templates (img src) #2231

alexsorokoletov opened this issue Sep 19, 2016 · 9 comments
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix

Comments

@alexsorokoletov
Copy link

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
OS X El Capitan
  1. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:
angular-cli: 1.0.0-beta.14
node: 6.3.0
os: darwin x64
  1. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.

Create new project with ng new test-project
Add images folder to src (and you can add to src/app, doesn't matter).
Reference image in app.component.html
<img src="images/image.png" alt="test" />
Build project with ng build -prod

  1. The log given by the failure. Normally this include a stack trace and some
    more information.
    Image is not being bundled into dist folder and is not loading producing 404 error.
  2. Mention any other details that might be useful.
    Problem is reproduced with ng build -prod and is not reproduced with ng serve -prod.
    github repo showing problem: https://github.com/alexsorokoletov/angular-cli-image-loader-problem

I am not sure if this is a problem of webpack html loader plugin or issue related to it's configuration or I am doing something wrong.
For a workaround I am using assets folder and put all images there.
However, it is strange to me keeping some images in assets and some (that are mentioned in the css files) inside the webpack bundle


Thanks! We'll be in touch soon.

@michaelpm91
Copy link

I've been having similar issues. In angular-cli.json in the apps array there's an assets key. When building the angular cli uses the directory you pass in there to bundle assets. You could change this to "assets": "images" or whatever.

@alexsorokoletov
Copy link
Author

Assets is a different story.
If you mention image.png in CSS, this image is bundled into styles.js.gz and loaded from this file without any additional request.

However, the asset images are just file copied to dist folder and are not optimized in any way.

Alex

On Sep 19, 2016, at 17:33, Michael Patterson-Muir notifications@github.com wrote:

I've been having similar issues. In angular-cli.json in the apps array there's an assets key. When building the angular cli uses the directory you pass in there to bundle assets. You could change this to "assets": "images" or whatever.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@filipesilva
Copy link
Contributor

As far as I can tell, we don't process html and just load it as is - but we process css and thus inline stuff.

@TheLarkInn is there a good way to inline images in html? https://github.com/webpack/html-loader seems to offer options to do it, but I get the feeling there was a reason why we didn't do that.

@filipesilva filipesilva added type: bug/fix command: build P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Sep 22, 2016
@alexsorokoletov
Copy link
Author

@filipesilva thank you for looking into this.
My understanding is that we can use similar approach as with css. I am not 100% sure about that and what webpack can actually do about that.

Would love to have a way to bundle images in html or other suggested way to have images in html optimized. Additionally, having a sample right inside a new project template would be awesome.

@TheLarkInn
Copy link
Member

I think we can simply do this through html-loader. There isn't a reason I see that we shouldn't. Let me whip up a PR for this.

@ghost
Copy link

ghost commented Sep 27, 2016

I've been having similar issues. In angular-cli.json in the apps array there's an assets key. When building the angular cli uses the directory you pass in there to bundle assets. You could change this to "assets": "images" or whatever.

What if I've got two folders with assets? Don't ask why, but I've got an "img" folder and an "images" folder. It does not seem to support an array.... @kidshenlong

@alexsorokoletov
Copy link
Author

This ticket as far as I know is not about assets folder and assets behavior

@filipesilva
Copy link
Contributor

We added this functionality in beta.16, but are actually looking at removing it due to #2396.

@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
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants