11

I have an npm package that has a number of angular components. In their templates, they reference images. If I copy the images to my application's images directory, the references resolve, but this feels stupid.

Is there a way to have webpack handle image writing so that when App B includes components from App A, the images work in the build and there's no manual copy step involved?

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
  • can you add folder structure and webpack config? – Thaadikkaaran Feb 01 '17 at 09:49
  • have you tried with https://github.com/tcoopman/image-webpack-loader ? – Carlos Feb 01 '17 at 17:54
  • @stefan, adding to what @Jaganathan said can you please share some code of what already has been done. Also do mention whether you are trying bundling in the `dev` env or `prod`. – debatanu Feb 05 '17 at 13:13
  • Answered this same question in my own question: https://stackoverflow.com/questions/45111478/angular-cli-how-to-reference-image-paths-in-reusable-components/45151203#45151203 – ruhler Jul 17 '17 at 18:42
  • Answered this question in my own question: https://stackoverflow.com/questions/45111478/angular-cli-how-to-reference-image-paths-in-reusable-components/45151203#45151203 – ruhler Jul 17 '17 at 18:43

1 Answers1

3

If images are not properly required in this npm package then webpack won't be able to process them. You may try something like copy-webpack-plugin or write own copy script to avoid manual copying

Slava.K
  • 3,073
  • 3
  • 17
  • 28
  • 1
    Probably the best answer. Just export the images in the library via package.json, and copy them to your images directory via gulp. There doesn't seem to be a better way to do this via webpack. – Stefan Kendall Feb 10 '17 at 18:02
  • Answered this question in my own question: https://stackoverflow.com/questions/45111478/angular-cli-how-to-reference-image-paths-in-reusable-components/45151203#45151203 – ruhler Jul 17 '17 at 18:44
  • @ruhler your question is about angular 2 and higher while this question is about AngularJS. These are different angulars – Slava.K Jul 20 '17 at 10:26