-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs for better Next.js integration #300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
* [Basic](#basic) | ||
* [Advanced](#advanced) | ||
* [TypeScript](#typescript) | ||
- [Integrating with other tools and frameworks](#integrating-with-other-tools-and-frameworks) | ||
* [ext.js](#extjs) | ||
- [Frequent questions](#frequent-questions) | ||
* [How do I import the same icon from two different styles?](#how-do-i-import-the-same-icon-from-two-different-styles) | ||
* [I don't think tree-shaking is working; got any advice?](#i-dont-think-tree-shaking-is-working-got-any-advice) | ||
|
@@ -531,6 +533,98 @@ They are re-exported from both `@fortawesome/fontawesome-svg-core` and | |
make importing more convenient in some cases. Refer to the `index.d.ts` in any | ||
module to see which types it exports. | ||
|
||
## Integrating with other tools and frameworks | ||
|
||
### ext.js | ||
|
||
Next.js projects will experience an icon that is very large when the page first | ||
loads. The reason this occurs is that the necessary CSS has not been loaded | ||
before the icon is displayed. | ||
|
||
To fix this we need to make sure the CSS for Font Awesome is bundled with the | ||
Next.js app. | ||
|
||
Install `@zeit/next-css`: | ||
|
||
``` | ||
npm install --save-dev @zeit-css | ||
``` | ||
|
||
You may want to use `--save` instead of `--save-dev` depending on how your `package.json` is organized. | ||
|
||
Create or edit `next.config.js` in the root of your project: | ||
|
||
```javascript | ||
const withCSS = require('@zeit/next-css') | ||
module.exports = withCSS({ | ||
/* config options here */ | ||
}) | ||
``` | ||
|
||
Create or edit `./pages/_app.js`: | ||
|
||
```javascript | ||
import React from 'react' | ||
import App, { Container } from 'next/app' | ||
|
||
import { config } from '@fortawesome/fontawesome-svg-core' | ||
import '@fortawesome/fontawesome-svg-core/styles.css' // Import the CSS | ||
config.autoAddCss = false // Tell Font Awesome to skip adding the CSS automatically since it's being imported above | ||
|
||
class MyApp extends App { | ||
render() { | ||
const { Component, pageProps } = this.props | ||
return <Component {...pageProps} /> | ||
} | ||
} | ||
|
||
export default MyApp | ||
``` | ||
|
||
You may also wish to include your library calls in the `_app.js` code. | ||
|
||
```javascript | ||
import React from 'react' | ||
import App, { Container } from 'next/app' | ||
|
||
import { config, library } from '@fortawesome/fontawesome-svg-core' | ||
import '@fortawesome/fontawesome-svg-core/styles.css' | ||
config.autoAddCss = false | ||
|
||
import { faBars, faUser } from '@fortawesome/free-solid-svg-icons' | ||
import { faTwitter, faFacebook } from '@fortawesome/free-brands-svg-icons' | ||
|
||
library.add(faBars, faUser, faTwitter, faFacebook) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just import them where they are used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a section below this to mention explicit import. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean; I tried both in a nextjs project and there seems to be no upside to doing |
||
|
||
class MyApp extends App { | ||
render() { | ||
const { Component, pageProps } = this.props | ||
return <Component {...pageProps} /> | ||
} | ||
} | ||
|
||
export default MyApp | ||
``` | ||
|
||
You can also use [explicit import](#explicit-import) instead of using the `library`. | ||
|
||
Create a new page: | ||
|
||
```javascript | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faThumbsUp } from '@fortawesome/free-solid-svg-icons' | ||
|
||
const Index = () => ( | ||
<div> | ||
<p> | ||
<FontAwesomeIcon icon={faThumbsUp} /> Hello Next.js | ||
</p> | ||
</div> | ||
) | ||
|
||
export default Index | ||
``` | ||
|
||
## Frequent questions | ||
|
||
### How do I import the same icon from two different styles? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.next | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const withCSS = require('@zeit/next-css') | ||
|
||
module.exports = withCSS({}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh. Thanks.