我正在使用@ ngtools / webpack学习angular 6,但在处理CSS时遇到问题。

我在webpack.config.js中有以下模块规则

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


当我使用Component.styleUrls时,角度编译器将使用“原始加载程序”并将Component.styleUrls内联到Component.styles。它工作正常。

然后我想安装“ ngx-toastr”,我补充说

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


到我的index.ts。它不起作用,因为在这里使用了'raw-loader'。

如何正确导入“ toastr.css”?

最佳答案

我认为,如果将CSS添加到“ .angular-cli.json”文件中的“样式”中,它将可以正常工作。
添加样式后,它应该看起来像这样

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

关于css - 使用@ ngtools/webpack时如何导入CSS?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51738468/

10-12 00:22
查看更多