next-style-loader
Makes loading of CSS files possibles in next.js projects through babel & webpack.
This project is similar to what webpack style-loader
does but is compatible with next.js
.
Installation
$ npm install --save-dev next-style-loader
Setup
First you will need to create a next.config.js
file:
moduleexports = { configmodulerules; return config; };
Finally, create a pages/_document.js
file:
;;; { const nextStyle = thisprops; return <html> <Head> nextStyletag </Head> <body> <Main /> <NextScript /> </body> </html> ; } MyDocument { const props = Document; propsnextStyle = ; return props;};
Usage
After setting the project, you may import CSS files like so:
; const MyComponent extends Component render return <div>Hello</div>; }} stylesMyComponent;
Enjoy!