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
webfonts
directory understatic
folder and rename it tofonts
- Create
styles
directory under the root folder - Copy
scss
directory tostyles
directory and rename it tofontawesome
- Open
_variables.scss
underfontawesome
directory and change$fa-font-path: "/static/fonts" !default;
- Create
styles.scss
understyles
folder 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";
Alternative way that doesn't use SCSS: https://github.com/UnlyEd/next-right-now
Interesting parts are:
https://github.com/UnlyEd/next-right-now/blob/master/src/components/Nav.tsx#L234 (usage)
https://github.com/UnlyEd/next-right-now/blob/master/src/pages/_app.tsx#L39-L42 (config)