0%

create-react-app使用CDN引入库

在 package.json 文件删除antd依赖。

https://www.jsdelivr.com/ 搜索antd得到js和css链接。

在 public/index.html ,放入js和css链接。

1
2
3
4
5
6
...
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/reset.min.css">
</head>
...
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/antd.min.js" integrity="sha256-eP2yKhOQWYkDmydKH19f+mBDhj1BpUJ38oSuLtK1NSk=" crossorigin="anonymous"></script>
</body>

然后在 src/index.js 中添加空白的导入语句

1
import 'antd';

禁用依赖检查,在 package.json 文件中添加以下配置:

1
2
3
"resolutions": {
"antd": "x.x.x" // x.x.x 是 Ant Design 的版本号
}

删除node_modules、yarn.lock,执行yarn install、yarn start即可。

欢迎关注我的其它发布渠道