-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Implement ant-design (antd) in create-react-app #2463
Comments
this would be really great. antd is really the most mature components framework so far, and even though it is obviously there fault that the library can't be used easily, it would be great if create-react-app could be used easily with antd. |
Hi! Unfortunately this is a design decision made by Ant Design; there's nothing we can do to support it out of the box without adding explicit integration with it. Since this is not used heavily by Facebook or any of our maintainers, adding integration is pretty much out of the question (sorry!). My suggestion would be to ask ant design to publish a webpack consumable / module friendly build or use a maintained The best solution would be a module-consumable build produced by Ant Design. |
I don’t understand why Ant docs recommend ejecting and using the Babel plugin. import Button from 'antd/lib/button';
import 'antd/lib/button/style'; This should work with Create React App. cc @afc163, would you be willing to amend the docs to recommend this approach for CRA integration rather than ejecting? It’s unfortunate when libraries prescribe people to change their build process. |
Yeap, I did it in that way. Ant-design says that you have to eject in case you want to import using this way: import Button from 'antd'; (and just that, with no style and |
That’s fair—I’m just saying that Ant’s “Usage with Create React App” page should probably mention that approach first, and only mention ejecting as last option. |
Tagging this as needing help. The actionable item is to submit a PR to Ant docs (or raise an issue) that changes use in create-react-app page to suggest the workaround above rather than ejecting. |
@gaearon On it |
Issue created: ant-design/ant-design#6371. |
In another hand. |
PR created in |
@gaearon antd uses less so we hav eto import css instead:
On the other hand, although eject is not needed to get it running, it is almost necessary in order to customize themes, which is a huge part of web development. |
@BrodaNoel do you have any advice for theming? |
@khankuan yeap. Check the PR: ant-design/ant-design#6375 |
Do you have a need to customize themes like colors in your project? |
The CSS is not that big. 43kb gzipped. So you can compile it statically into a themed file and import it in you index.html. |
See example less theme here: Which is compile with You'd have to adjust the directory structure of course in create React app. |
@MrLoh Thanks for the tip! Do you have need for reusing variables such as colors in CRA for an in-house component that is outside of antd? |
Yeah sure that comes up. But it's not that much overhead two copy a handful of established color values. Mainly I need colors in SVG components outside of antd |
@MrLoh I've tried your example with
I think it cannot resolve the relative paths of antd? |
@afc163 Thank you! using less@2.7.2 worked! |
(create react app + typescript + antd) without eject and without using Babel. https://github.com/qinyang1980/create-react-antd-app.git |
(create react app + typescript + antd) $ yarn add ts-import-plugin --save in webpack.config.js const tsImportPluginFactory = require('ts-import-plugin');
const antdTransformer = tsImportPluginFactory({
libraryName: 'antd',
libraryDirectory: 'lib',
style: 'css'
});
{
test: /\.(ts|tsx)$/,
include: paths.appSrc,
use: [{
loader: require.resolve('ts-loader'),
options: {
getCustomTransformers: () => ({ before: [antdTransformer] }),
// disable type checker - we will use it in fork plugin
transpileOnly: true
}
}]
}, then import antd component: import { Button } from 'antd';
<div>
<Button type="primary">Primary</Button>
<Button>Default</Button>
<Button type="dashed">Dashed</Button>
<Button type="danger">Danger</Button>
</div> |
Check this out. They added docs about how we can use Antd with CRA |
@ani-naslyan that documentation was there for a few years ago. Check the firsts lines of that documentation:
"and modify the webpack config " <<< |
Hi guys.
As you may know, ant-design is being sort of popular in these last days, but the implementation require
eject
CRA
if you want to implement it in the best performant way.More info:
Is there a way to implement ant-design, with no ejecting
CRA
?The text was updated successfully, but these errors were encountered: