Css pollution problem

there are two React projects An and B, Project B is a public project, and Project A depends on Project B.
they all rely on the antd component library, but with different versions.

now the way to use B in An is to build, first and then introduce:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>app</title>
    <link rel="stylesheet" href="path/to/project/B.css" />
    <link rel="stylesheet" href="path/to/project/A.css" />
</head>

<body>
    <div id="root_a"></div>
    <div id="root_b"></div>
    <script src="path/to/project/bundleB.js"></script>
    <script src="path/to/project/bundleA.js"></script>
</body>

</html>

the problem is that both A.css and B.css contain antd.css, that can cause pollution. But because the version is different, we can"t just quote one.

trying to wrap a layer of Id, around project B antd.css is similar to -sharproot_b .antd _ xxx {} , but it doesn"t seem to work:

// b_index.less
-sharproot_b{
    @import "~antd/dist/antd.css";
    
    //
}

find a solution ~


1. If you say that Project A depends on Project B and Project B is a public project, see if you can dynamically use different versions of antd referenced versions when loading A;
2. Basically, it's best to separate or use the same version of the repository

.

ps: No matter what you do, even if you solve a short-term problem, it is not a long-term solution, and it will lead to a lot of more complex style problems. Therefore, it is recommended that you take a long-term view, since it is a mutually exclusive relationship, then to the point, An and B separate warehouses do not rely on, or merged into one.

Menu