Install these two plugins:
const withSass = require("@zeit/next-sass");
const withFonts = require("next-fonts");
module.exports = withFonts(
withSass({
webpack(config, options) {
// custom webpack loaders if you need
return config;
}
})
);- Download FontAwesome and extract the file
- Copy
webfontsdirectory understaticfolder and rename it tofonts - Create
stylesdirectory under the root folder - Copy
scssdirectory tostylesdirectory and rename it tofontawesome - Open
_variables.scssunderfontawesomedirectory and change$fa-font-path: "/static/fonts" !default; - Create
styles.scssunderstylesfolder and paste the following:
@import "./fontawesome/fontawesome";
@import "./fontawesome/fa-brands";
@import "./fontawesome/fa-regular";
@import "./fontawesome/fa-solid";Create below _document.js under pages directory.
import Document, { Head, Main, NextScript } from "next/document";
export default class MyDocument extends Document {
render() {
return (
<html>
<Head>
<link rel="stylesheet" href="/_next/static/style.css" />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}Import SCSS to your Layout component or wherever you like that you want to use FontAwesome:
import "../styles/styles.scss";