Work with antd?
I'm trying to get nextjs to work with antd but get
"You may need an appropriate loader to handle this file type."
What do I need to do in order to get these things working together? Thanks.
May be that's related to importing .css files.
Currently, we don't support importing custom modules.
Even if you've added a correct webpack-loader, it won't work since SSR env cannot import that.
https://github.com/ant-design/babel-plugin-import#via-babelrc
This is no help then. Is custom modules on the map, or not so much because of SSR?
We wanted to support it. But I think we need to work a bit harder for that. So, that's after a priority after 2.0
Thanks Arunoda! I seem to have followed you from meteor. Nice to see you around.
Is is still planned for after 2.0? Should this be reopened then?
+1 for antd
feature supported now? I am tring to use antd with nextjs
@liadbiz have a look here https://github.com/zeit/next.js/issues/544
@timneutkens thanks. I will give feedback after tring.
Just thought I'd chime in since this seems to be a bit of a tricky issue in next.js. Anyhow here's how I'm able to use antd's css imports in my project: https://github.com/zeit/next.js/issues/544#issuecomment-280190145
@jozanza do you have a working example of this? Where you render an antd component? And how you then import the css? Because I can't make it work :'(
@AugustinLF I've figured out an example if you're interested. I haven't made a really in depth application so I don't know if any other problems exist yet, but I've been able to import a Button component and have it display.
If you clone this example: https://github.com/zeit/next.js/tree/master/examples/with-global-stylesheet
Then import that antd styling like so in an app level component.
components/App.js
import styles from 'antd/dist/antd.css';
export default ({ children }) => (
<main>
<style dangerouslySetInnerHTML={{ __html: styles}} />
{children}
</main>
)
Then in any of your pages, I'm using index.js as an example:
import App from '../components/App'
import Header from '../components/Header'
import withData from '../lib/withData'
import { Button } from 'antd';
export default withData((props) => (
<App >
<Header pathname={props.url.pathname} />
<Button>Test</Button>
</App>
))
And voila you have an antd styled button. Again, I'm still learning to see if this works without issue, so I'm going to continue playing with this solution. Unfortunately I haven't found a solution for importing a single component's set of styles at a time so this will be kind of expensive over the network.
Yes, thank you, it worked out for me!
Yeah, that works pretty well. You can also enable global imports like this import { Button, Input, Form } from 'antd' by using the babel-plugin-import. Loading all the CSS is not such a big issue, since it is just 43 KB gzipped.
#484
Do you recommend the approach from @blakedietz ?
I compiled the less files in the static folder, since I needed my own theming and then just added a style tag, but the end result is about the same I think
OK, I solved it, but you must to import the whole css, such as me, I import the css file in Head. Just see the code:
layout/index.js
import Head from 'next/head'
export default ({children}) => (
<div>
<Head>
<link rel='stylesheet' href='http://cdn.bootcss.com/antd/2.9.3/antd.css' />
</Head>
{children}
</div>
)
pages/index.js
import React from 'react'
import Layout from '../layout'
import { Button } from 'antd'
export default () => (
<Layout>
<Button type="primary">Primary</Button>
</Layout>
)
And to import on demand, we should add babel plugins, please run npm install -D babel-plugin-import at first.
.babelrc
{
"presets": ["next/babel"],
"plugins": [
["import", {
"libraryName": "antd",
"style": false
}]
]
}
That's all, good luck to you!
This issue still exists today. it seems SSR just won't support global css import.
I'm also having this issue. I'm trying to import semantic.min.css but couldn't. Throws me an error.