-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Work with antd? #484
Comments
May be that's related to importing 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. |
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 |
@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. |
@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.
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 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 |
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:
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
{
"presets": ["next/babel"],
"plugins": [
["import", {
"libraryName": "antd",
"style": false
}]
]
} That's all, good luck to you! |
This issue still exists today. |
I'm also having this issue. I'm trying to import semantic.min.css but couldn't. Throws me an error. |
any way to do it without linking to an external stylesheet? Would like to keep everything in JS if possible.. |
I was able to theme couple of caveats:
Here is my
Then in my layout component below the next.js
|
this works as a charm:
|
@truca why didn't you make use of this? isn't this possible in latest next? I suppose that inline approach imports entire ant stylesheet, will that not affect loading performance? |
Just tested antd with the new next-less plugin for next v5.x and it works great when pointing it directly to Only note is that antd isn't compatible with the new less v3.x yet, had to revert to v2.7 This is still including the entire style. @crushy26 yes, since the latest next now runs webpack on the server side, it should be possible to use |
@kriscarle do you have an example of what you did? |
Look at the of this example and you can make it work. https://github.com/zeit/next.js/tree/canary/examples/with-ant-design |
@amrdraz here is a Gist with my current config, it supports a custom theme, but still includes the entire style: https://gist.github.com/kriscarle/d3136e9b15634846036397409bf98214 @and3rsonsousa thanks! I hadn't noticed that the example was updated. It is still using the css option in |
You just have to see the example on Ant site abou using less. I did it and it was very easy to configure. |
i've tried a dozen different ways of achieving
Now, ideally, we could do this:
... which would scope styles locally, which is great. but as of next 3/4 (when I set this up), something was stopping that from working. So, I used The big pro with this approach is that all the CSS is inlined, so it lands in the client rendered and ready (also helps w/ page speed, per google pagespeed insights). The cons are that it's a pain in the ass to set up, plus a few gotchas:
Oh, and if you're using
|
i got modular antd imports working with so far i've been seeing decent size improvements vs. including the entire antd less file (especially minified). you can configure theme overrides with
then remove it and move your overrides over to |
@delikat :Hi, There is an example with Antd + LESS. 😄 |
@delikat Awesome, thank you for figuring it out! I was completely defeated by this, too much Webpack magic required :) @giautm in your example, it looks like the next-less plugin is still importing the entire style file? Probably fine for most people and definitely is a much cleaner config in Next. The |
Actually it looks like we can simplify the required custom config by following the |
@delikat hi, your gist ran into this error on Production start, look like it was not processed by
|
hi @giautm, yes it looks like overriding |
@delikat It's still not working. Update: Yah, I found it in the first version of your gist. It's worked |
@delikat It work, big thank 👍 |
@delikat It work,thx,but cssModules can't work again ! |
I tried creating a few more pages following the with-ant-design/index.js pattern and the css fails to load when you click the new pages. (with-ant-design-less didn't seem to have this problem) Could someone confirm I am not crazy that the with-ant-design example pattern has css loading issues if add new antd components to new pages and click around? I don't want new users to hit a brick wall when they try to scale out the example to more pages. I assume the "transform-decorators-legacy" stuff in package.js and .babelrc is no longer necessary with next6 because next6 uses babel7? I would appreciate if someone who knows can confirm/deny that before I do push request to remove something I don't understand. The example code would be better starting point for new users if it was using modular imports...antd css is just too big for production. Just adding antd dependency made my release zip go from 20m to 50m (insert swearing here). The example from @delikat seems to work...anyone object to it being part of the example? Note that I had some trouble using it with next 6 so my fixes are here with notes in comments: https://gist.github.com/Enalmada/c0a83bbc639aae5d4504527a0fe18f41 So why does HMR not work with this solution? Could someone elaborate on that please? I am curious if it is a solvable problem? |
I asked for more help #5180 |
Thank you, this helped me get it working! |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
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.
The text was updated successfully, but these errors were encountered: