Correct way to use image assets in Ionic 2

前端 未结 4 1485
一向
一向 2021-01-31 07:51

What’s the best practice for image assets in Ionic 2? I have a bunch of SVGs I want to use as non-system icons. I found some older tips on using Gulp but it seems Ionic team has

相关标签:
4条回答
  • 2021-01-31 08:11

    [...] it seems Ionic team has decided on Rollup as the build tool of choice, no docs on this so far.

    Seems like you're asking how to manage images with the new RC.0

    Just like you can see in the conference app the images are stored in src/assets/img and then you can add them to your html code like this:

    <img src="assets/img/myImg.png">
    

    This is one of the steps mentioned in the Modifying your Existing Project guide (step 31 to be precise), so I guess this is what Ionic team recommends.

    0 讨论(0)
  • 2021-01-31 08:13

    in my case, I had to replace /assets/img/... with assets/img/... (removed the / )

    the first works in ionic serve but not on Android

    0 讨论(0)
  • 2021-01-31 08:24

    @ionic/app-scripts : 3.1.8

    The below src path worked for me in Ionic 3.(prefixed ../ before assets)

    <img src="../assets/imgs/{{item.titleID}}.svg" alt="{{item.title_desc}}">
    
    0 讨论(0)
  • 2021-01-31 08:30

    Placing your images in www/img sounds like a good ideal but it will only work when serving locally using ionic serve.

    When building your app, the www/img will get deleted unless you make a gulp task to copy the images from the folder you want to the www/build folder as shown in this post.

    Images used in html files should be in src/assets/img(recommended) and not www/assets/img(obselete). Image tags would then look like this :

    <img src="assets/img/yourimage.jpg" alt="your image">
    

    In ionic 2, the src/assets folder is meant for images and fonts.

    This is what the ionic team says in the guide to modify an existing ionic project :

    1. Move www/img to src/assets/img.

    2. Move any other resources you have in www/ to src/assets/.

    0 讨论(0)
提交回复
热议问题