简体   繁体   中英

How do I import css when using @ngtools/webpack?

I am learning angular 6 with @ngtools/webpack and I got a problem with dealing with css.

I have the following module rules in webpack.config.js

module: {
    rules: [
        { test: /\.ts$/, loader: '@ngtools/webpack' },
        { test: /\.html$/, loader: 'raw-loader' },
        { test: /\.css$/, loader: 'raw-loader' }
    ]
}

When I use Component.styleUrls, the angular compiler will use the 'raw-loader' and inline the Component.styleUrls to Component.styles. It works fine.

Then I want to install 'ngx-toastr', I added

import './../node_modules/ngx-toastr/toastr.css';

to my index.ts. It doesn't work because 'raw-loader' is used here.

How can I correctly import 'toastr.css'?

I think if you add that css to "style" in ".angular-cli.json" file it will work fine. after adding to style it should look like this

"styles": [
    "styles.css",
    "node_modules/bootstrap/ngx-toastr/toastr.css"
  ]

Can you create anycomponent.scss file, import the toastr.scss file using relative file path.

import './../node_modules/ngx-toastr/toastr.css';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM