Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my CSS files ignored with Angular CLI when in prod mode?

Tags:

angular-cli

I have what I think is a standard .angular-cli.json file. In apps[0] it has:

  "styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],

The above works fine with an "ng build" or an "ng serve". However, if I do an "ng build --prod" these two css files are ignored. The way I am getting around this is by using a CDN version of bootstrap.min.css and adding styles.css to a publicly available resource (Azure blog storage) and then referencing them from index.html.

FWIW, if I do an "ng serve --prod" it still works in my localhost/dev environment. But "ng build --prod" does not.

Any ideas where to start?

like image 993
Kirk Liemohn Avatar asked Oct 30 '17 11:10

Kirk Liemohn


People also ask

Can I use CSS and SCSS in angular?

With the help of Angular CLI, you can install CSS or SCSS on your project and start working on that in a suitable way. If you are working with the CSS or SCSS in your angular project then it is very easy for you as compared to most other frameworks.


1 Answers

you have this problem because of the order of css file when bundling them, the only possible solution now is to let only style.css file like this:

 "styles": [
   "styles.css"
  ],

and import bootstrap.min.css inside your style.css

@import url("../node_modules/bootstrap/dist/css/bootstrap.min.css");

that willmake your app work in local and prod, the alternative solution is build with --extract-css=false

ng build --prod --extract-css=false
like image 148
Fateh Mohamed Avatar answered Sep 20 '22 15:09

Fateh Mohamed