Problem
After generating a workspace with the new @angular/cli@18
package, I am unable to determine how to reference image assets placed in the /public
folder.
This did not seem to be an issue with @angular/cli@17
workspaces but they used a different asset folder name & location.
Background
For comparison, v17 created a structure similar to this when using the ng new workspace-name --no-create-application
command and then ng g app application-name
inside that workspace:
workspace-name
|
projects
|
application-name
|
src
|
assets
Then, from a template you could reference an asset like so: <img src="assets/imagename.webp">
However, in v18 the created structure is generated as follows when using commands similar to above:
workspace-name
|
projects
|
application-name
|
public
src
It appears that the assets are intended to go in the public folder but I have tried various permutations of pathing to reference these assets to no avail. Also, doing an ng build application-name does not appear to copy the files in the public folder over to the dist so maybe this has something to do with it.
It should be noted that when an app is generated without a workspace, I am able to reference assets simply by using asset-name.webp
without issue. Additionally, the v18 workspace angular.json
file has the following configuration automatically set for the assets
property of the application build options:
"assets": [
{
"glob": "**/*",
"input": "public"
}
]
Question
Is this a bug with the new builder or is there a new way to reference these assets or some additional configuration that needs to be done now that they are located in a different folder?
Solution
After doing a little investigating it looks like the cli did not set the projects.applicationName.architect.build.assets
property in the angular.json
file properly. Changing over the input
property from public
to projects/applicationName/public
did the trick. Now I am able to reference assets simply with asset-name.webp
.