【问题标题】:What is the differences with having a `<link rel="stylesheet" href=..video.scss` in the index.html vs using `import '../video.scss`在 index.html 中使用 `<link rel="stylesheet" href=..video.scss` 与使用 `import '../video.scss` 有什么区别
【发布时间】:2020-09-12 20:00:26
【问题描述】:

我是 Reactjs、Javascript 的初学者,正在学习一些教程和注意事项
对于样式表,有些人在 React Component 中这样做:

import '../../styles/video.scss

有些人在 index.html 中这样做:

<link rel="stylesheet" href="./css/styles.css">

何时使用 ReactJs 和首选使用什么

【问题讨论】:

    标签: css reactjs stylesheet


    【解决方案1】:
    import '../../styles/video.scss'
    

    这绝对是要走的路。

    主要区别在于以这种方式导入的东西将通过 webpack 管道拉取,例如加载器。负责转译 SASS 的加载程序会查找 ES6 导入,但它无法转译索引中的 links。简单来说,你不能将 sass & friends 导入为link

    另一件事是你不断地把东西扔进索引,它会增长得非常快并且变得一团糟。

    此外,您的案例仅提及全局 css 导入,这是您唯一可以通过索引内的 link 执行的操作。模块化 css 之类的东西只能作为模块导入使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2020-06-17
      • 2011-09-08
      • 2015-01-14
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      相关资源
      最近更新 更多