Issue with locating assets in Angular 6 build

Hey there! I'm currently facing an issue while trying to build my angular project. In the project, I am using scss with assets, and below is a snippet of how I have defined the background image:

.ciao {
  background-image: url("../../assets/images/bck--registration-company.png");
}

When running the following code:

ng build --prod --configuration=coll --base-href ./

I find the file "bck--registration-company.png" within the dist folder, located in the same directory as index.html. Additionally, there is another "bck--registration-company.png" inside the "assets" folder, which has me wanting to utilize resources from this folder.

I've experimented with various modifications such as changing the base href and altering the relative/absolute image paths, but without any success. Here's an example:

.background--image-carousel2{
  background-image: url("/assets/images/carousel2.jpg");
}

However, this path results in a REQUEST URL as follows:

Request URL: http://localhost:63342/assets/images/carousel2.jpg

This URL is incorrect as it should ideally be:

http://localhost:63342/project/dist/name_project/assets/images/bck--registration-company.png

In my angular.json configuration, you can find the following setup:

"architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/name_project",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/assets"
        ],
        "styles": [
          "src/styles.scss"
        ],
        "scripts": [

        ]
      },

If you have any insights on how I could resolve this matter, I would greatly appreciate your help. Thank you!

Answer №1

Give this method a try

Angular has direct access to the assets folder.

.hello {
   background-image: url("assets/images/background-company.png");
}

Next, execute a build command

ng build --prod 

After that, insert the entire system path into the dist/index.html file

In the base url, specify the complete path of the project directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

NextImage encountering issues in Internet Explorer 11

In my TypeScript setup, here is a snippet from my package.json file: "dependencies": { "@tailwindcss/typography": "^0.4.1", "@webcomponents/shadydom": "^1.7.4", "cookie": "^0.4.1", " ...

What possible reasons could cause the installation of Visual Studio 2017 to disrupt node.js or the typescript compiler?

Recently, I updated to the latest version of Visual Studio 2017 and selected the node.js support option during installation. However, after this update, I encountered issues with the typescript compiler (tsc) in an Angular 2 project that was last modified ...

Uploading videos on Mobile Safari causes the website to refresh automatically

Setting up a photo uploading server on a raspberry pi using Angular with Node.Js and multer has been an exciting project for me. I opted to host it on an unsecured ad-hoc network created by the pi itself so I can easily take it on road trips and store phot ...

What is the best way to retrieve both the checked and unchecked values from a collection of checkboxes?

Check Out This live Example: I am in the process of creating a list of checkboxes with various data objects: data = [ { Key: "class_id", displayName: "Section ID", enabled: true }, { Key: "room_l4", displayName: "Location", enabled: false }, { Key: "se ...

Angular 2: Changing the name of a component

Looking for guidance on renaming a component in my Angular2 application. I've already updated all the necessary files - changed the file names and folder name, as well as made adjustments to specific files such as y.component.ts, app.routing.ts, and a ...

Combine individual websites that have been deployed separately into a single website and display them using a uniform base URL

I have multiple website projects deployed on separate subdomains with their specific resources. I want to create a launch/landing subdomain website that allows users to access each website in different subdomains through the menu, without changing the subd ...

Implementing interactive dropdown menus to trigger specific actions

I have modified some code I found in a tutorial on creating hoverable dropdowns from W3. Instead of the default behavior where clicking on a link takes you to another page, I want to pass a value to a function when a user clicks. Below is a snippet of the ...

Having trouble compiling Angular CLI version 8.3.21 with the command ng serve

Upon trying to compile my first Angular app, I encountered an error when running ng serve: ERROR in ./src/styles.css (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded! ...

Modifying the response header in a node.js middleware: A step-by-step guide

I've been researching this question extensively on Google, but unfortunately, none of the solutions seem to work for me. The issue I'm facing is related to adding a specific property to the response header called "isAuth," which needs to be set ...

Sacrificing type safety versus retaining type safety

I'm curious to know what sets apart these two approaches when declaring the status property. I understand that the second version maintains type safety, but how exactly does it achieve this? export type OwnProps = { id: number; name: string; sta ...

Encountering a "breaks the Content Security Policy directive: 'default-src 'none''" message while trying to deploy an Angular application on Heroku

I've been encountering difficulties while attempting to deploy my Angular app on Heroku. An error message keeps popping up stating that the image '' violates the Content Security Policy directive: "default-src 'none'". Even though ...

A different component experiences an issue where Angular Promise is returning undefined

This is the carComponent.ts file containing the following method: async Download() { try { const settings = { kit: true, tyres: true, serviced: false, }; const [kits, tyres] = await Promise.all([ this.c ...

Encountering the following error message: "E11000 duplicate key error collection"

Currently, I am in the process of developing an ecommerce platform using the MERN stack combined with TypeScript. As part of this project, I am working on a feature that allows users to provide reviews for products. The goal is to limit each user to only o ...

Refreshing rows in ngx-datatable

Just started using ngx-datatable (version 11) with Angular-5 and encountered an issue. When loading rows during ngInit, everything works fine. However, when lazy-loading due to a user search request, the table shows the correct total number of rows but onl ...

Caution in version 3.5.1 of Vue Router: The tag prop of `<router-link>` is now obsolete and has been eliminated in Vue Router 4

After updating the node packages of our Vue.js app, a warning is now appearing in the browser console: [vue-router] The 'tag' prop has been deprecated and removed in Vue Router 4. To remove this warning, use the v-slot API. Check out the migrat ...

Trigger @HostListener event after a certain delay

I am currently working on implementing a basic infinite-scroll directive in Angular2. To achieve this, I am utilizing @HostListener('window:scroll') to capture the scroll event and extract the data from the $target. My concern is that every time ...

Executing various tasks concurrently with web workers in Node.js

Looking to read multiple JSON files simultaneously and consolidate the data into a single array for processing on a Node.js server. Interested in running these file readings and processing tasks concurrently using web workers. Despite finding informative ...

Angular 2+ integration with Font Awesome 5

I'm having trouble adding FontAwesome 5 to my Angular 2+ application. I came across this package - https://www.npmjs.com/package/@fortawesome/fontawesome Can you guide me on how and where to import this package? Should I do it in the app.module.ts fil ...

React Material Select: The error is caused by the property 'renderValue' with an expected type, as declared within the 'IntrinsicAttributes & SelectProps' type

Encountering an error with React Material Select, specifically on the Render Value function. How can I resolve this issue while using TypeScript? What should be added to the renderValue line? Error: Type '(selected: Array<number>) => string& ...

Is it possible to compile using Angular sources while in Ivy's partial compilation mode?

Error: NG3001 Unsupported private class ObjectsComponent. The class is visible to consumers via MasterLibraryLibModule -> ObjectsComponent, but is not exported from the top-level library entrypoint. 11 export class ObjectsComponent implements OnInit { ...