Created
February 15, 2021 13:39
-
-
Save smeijer/9d56c86b68479058478063cb6e817397 to your computer and use it in GitHub Desktop.
Revisions
-
smeijer created this gist
Feb 15, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ My config for using `twind/shim` with `next.js`, as used for [rake.red](https://rake.red/) Github Gists don't like slashes in names, so be sure to move `.twind.config.js` out of the `pages` folder. ``` ./twind.config.js ./pages/_app.js ./pages/_document.js ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ import App from 'next/app' import { setup } from 'twind/shim'; import twindConfig from './twind.config'; // If this run on the server _document.js has already done the setup if (typeof window !== 'undefined') { setup(twindConfig); } export default App; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ import Document from 'next/document'; import React from 'react' import { setup } from 'twind'; import { asyncVirtualSheet, shim, getStyleTagProperties } from 'twind/server'; import twindConfig from './twind.config'; const sheet = asyncVirtualSheet(); setup({ ...twindConfig, sheet }); export default class MyDocument extends Document { static async getInitialProps(ctx) { sheet.reset(); const initialProps = await Document.getInitialProps(ctx); initialProps.html = shim(initialProps.html); const { id, textContent } = getStyleTagProperties(sheet); const styleProps = { id, key: id, dangerouslySetInnerHTML: { __html: textContent, }, }; return { ...initialProps, styles: [ ...initialProps.styles, React.createElement('style', styleProps), ], }; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ export default { mode: process.env.NODE_ENV === 'production' ? 'silent' : 'warn', theme: { extend: { flex: { 0: '0 0 auto', }, fontFamily: { sans: ['Inter', 'sans-serif'], }, }, }, };