我开始玩Create React App,但我无法理解它index.js
是如何加载的index.html
.HTML代码是这样的:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a …
Run Code Online (Sandbox Code Playgroud) 我有一些颜色定义的变量到_colors.scss
文件中。
$color-succcess: #706caa;
$color-error: #dc3545;
Run Code Online (Sandbox Code Playgroud)
我还想将它们用于一些样式化的 React 组件react-table
到我的 js 文件中。
我使用以下文章https://til.hashrocket.com/posts/sxbrscjuqu-share-scss-variables-with-javascript作为参考,还有许多其他人喜欢它,但我无法让它工作。
我从我的 scss 文件中导出颜色:
:export {
colorSuccess: $color-succcess;
colorError: $color-error;
}
Run Code Online (Sandbox Code Playgroud)
我将它们导入到我的 js 文件中:
import colors from "../../styles/_colors.scss";
但他们可能没有正确加载。
我如何配置 create-react-app 生成的代码以实现与文章中的人使用 webpack 所做的相同的事情。