Angular引入node_modules里面的css文件出错Module build failed:TypeError:URL.startsWith is not a function

骑猪看日落 2022-05-31 03:09 667阅读 0赞

SouthEast

问题困扰了好几天,原来是路径的问题。

1.目录结构如下:

SouthEast 1

2.webpack配置:

  1. "include": [
  2. path.join(process.cwd(), "src/styles.css")
  3. ],
  4. "test": /\.css$/,
  5. "use": [
  6. "style-loader",
  7. {
  8. "loader": "css-loader",
  9. "options": {
  10. "sourceMap": false,
  11. "importLoaders": 1
  12. }
  13. },
  14. {
  15. "loader": "postcss-loader",
  16. "options": {
  17. "ident": "postcss",
  18. "plugins": postcssPlugins
  19. }
  20. }
  21. ]

3.在styles.css中引入( 路径很重要):

  1. @import '~/../node_modules/@angular/material/prebuilt-themes/indigo-pink.css';

注:所有在styles里面import的css文件都会被webpack打包到style.css,所以如果两个css对同一个元素标签起作用,请把要实现的样式import到后面。也就是重要的放在后面。

发表评论

表情:
评论列表 (有 0 条评论,667人围观)

还没有评论,来说两句吧...

相关阅读