0

I created an Angular application using ng new my-application command. Also I created a library in this application using ng generate library my-lib.

Here is a simple CSS code with background-image property. The image file does not exist

.class1 {
  background-image: url('./not-existing-file.png');
}

If I put this CSS code in the library projects/my-lib/src/lib/my-lib.component.scss and run ng build my-lib then the library will build successfully.

But if I put this CSS code in the src folder src/app/app.component.scss and run ng build then I get error:

NonErrorEmittedError: (Emitted value instead of an instance of Error) CssSyntaxError: C:\app.component.scss:2:2: Can't resolve '../not-existing-file.png' in 'C:\angular-tour-of-heroes\src\app'

I need to disable URL checks in CSS in ng build command, like in ng build my-lib. Is it possible?

1 Answer 1

1

You need to disable url(...) processing in your css-loader plugin (which again requires using an external web pack config). Basically do the following in your web-pack config.

{loader: 'css-loader', options: {url: false}}

But I suggest inlining the images in your library only. That way during compilation your image path would be replaced with data uris. You just have to set "cssUrl": "inline" in your libraries ng-package.json to make this working.

{
  "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
  "lib": {
    "cssUrl": "inline",
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.