I always see www as a goal of the build. So basically I always think that when I start a build that directory could be fully cleaned to be sure that all the last changes were included.
Furthermore, I don’t add the www folder to git.
Note: Right now, the build doesn’t copy anymore automatically what’s in assets (see https://github.com/driftyco/ionic-app-scripts/issues/176) to www/assets. So when I had something new I also mirror it manually to www/assets. But as soon as this gonna be fixed, everything gonna be fine. **
shorten
My files are in: src/assets/img
When building (or to deploy them manually), goal folder: www/assets/img
How to use them in code: < img src=“assets/img/my_img.svg”/ >
Tested on physical android phone and iphone
** Update: Seems that issue with app-script 0.0.36 gonna be fixed in 0.0.37
Just adding my 2c, The post above is the proper way to write the src.
*** DO NOT USE ***
src="/assets/img/jeff.img"
Since this will work fine on desktop browsers but fails on android devices/emulators. (Haven’t tried ios yet). This little snag cost me almost 2 days barking up the wrong tree (is it caused by browser incompatibilities? is it caused by CSP? etc).
This is different but related…
I am not trying to reference an image but rather a file that is storing some predefined data that my app needs.
I am also using the assets folder, like this
/src/assets/data/datafile.ts
In one of my services I am referencing the data file like this
import { DATA } from ‘…/…/assets/data/datafile’;
Now everything works fine when I use ionic serve or ionic emulate with liveReload.
BUT if I use it without liveReload my app loads up with a white screen and using chrome inspector I find that the error is
main.js:6Uncaught Error: Cannot find module “…/…/assets/data/datafile”
Can someone explain this one?? Seems like when using the /src/assets folder there is a difference between using liveReload or not.
I assume the same will happen for images?
I was actually referencing the data file from a component class (ie not from the html) and nothing seemed to work (ie not even jumping 1 level up @ryanlogsdon
I decided that for files being referenced from within the component class its better to move those out of the assets folder and into the app folders like all other classes.
It seems the assets folder should only be used when referencing items from the template itself (like images).
I copied image file into src\assets,
in browser both of these works fine
background-image: url(’…/…/assets/background.png’);
background-image: url(’/assets/background.png’);