fontawesome风格的图标在vite.js中不起作用。你可以简单地创建一个vite应用程序,然后添加fontawesome到它,你会注意到它。
错误:
Uncaught ReferenceError: process is not defined
at node_modules/path-parse/index.js (index.js:3:17)
at __require2 (chunk-S5KM4IGW.js?v=f1e39289:18:50)
at node_modules/resolve/lib/node-modules-paths.js (node-modules-paths.js:2:27)
at __require2 (chunk-S5KM4IGW.js?v=f1e39289:18:50)
at node_modules/resolve/lib/async.js (async.js:5:24)
at __require2 (chunk-S5KM4IGW.js?v=f1e39289:18:50)
at node_modules/resolve/index.js (index.js:1:13)
at __require2 (chunk-S5KM4IGW.js?v=f1e39289:18:50)
at node_modules/babel-plugin-macros/dist/index.js (index.js:5:17)
at __require2 (chunk-S5KM4IGW.js?v=f1e39289:18:50)
App.jsx:
import "./App.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
solid,
regular,
brands,
icon,
} from "@fortawesome/fontawesome-svg-core/import.macro";
function App() {
return (
<div className="App">
<FontAwesomeIcon icon={solid("user-secret")} />
<FontAwesomeIcon icon={regular("coffee")} />
<FontAwesomeIcon icon={icon({ name: "coffee", style: "solid" })} />
<FontAwesomeIcon ic on={brands("twitter")} />
</div>
);
}
export default App;
Fontawesome文档关于此主题:https://fontawesome.com/docs/web/use-with/react/add-icons
2条答案
按热度按时间fcg9iug31#
npm安装--开发vite插件babel宏
vite.config.js:
在babel-plugin-macros.config.js中
缺少的链接是package.json将类型“module”替换为“commonjs”
q35jwt9p2#
据我所知,您使用的是React,因此您实际上可以:
选择你想要的图标,固体,品牌等...:
然后:
除了像我上面所做的那样安装包和使用外,您不需要做任何其他事情。