Files
ant-design/docs/react/use-with-create-react-app.html
T
2017-01-07 23:41:51 +08:00

169 lines
44 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="An enterprise-class UI design language and React-based implementation">
<meta name="description" content="A set of high-quality React components">
<meta name="description" content="One of best React UI library for enterprise background">
<title>Ant Design - One Design Language</title>
<link rel="icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.cnpmjs.org/css?family=Lato:400,700|Raleway"/>
<link rel="stylesheet" type="text/css" href="/index-1.css"/>
<link rel="stylesheet" type="text/css" href="/index-2.css"/>
<style id="nprogress-style">
#nprogress { display: none }
</style>
<!--[if lte IE 10]>
<script
src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,media-match/2.0.2/media.match.min.js"></script>
<![endif]-->
<script>
if (!window.Intl) {
document.writeln('<script src="https://as.alipayobjects.com/g/component/intl/1.0.1/??Intl.js,locale-data/jsonp/en.js,locale-data/jsonp/zh.js">' + '<' + '/script>');
}
if (!window.Promise) {
document.writeln('<script src="https://as.alipayobjects.com/g/component/es6-promise/3.2.2/es6-promise.min.js"' + '>' + '<' + '/' + 'script>');
}
</script>
<script>
// Enable Google Analytics
if (!location.port) {
/* eslint-disable */
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-72788897-1', 'auto');
ga('send', 'pageview');
/* eslint-enable */
}
</script>
</head>
<body>
<div id="react-content">
<div class="page-wrapper" data-reactroot="" data-reactid="1" data-react-checksum="1739656478"><header id="header" class="clearfix" data-reactid="2"><div class="ant-row" data-reactid="3"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-4" data-reactid="4"><a id="logo" href="/" data-reactid="5"><img alt="logo" src="https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg" data-reactid="6"/><span data-reactid="7">Ant Design</span></a></div><div class="ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-20" data-reactid="8"><div id="search-box" data-reactid="9"><div class="ant-select ant-select-combobox ant-select-enabled" data-reactid="10"><div class="ant-select-selection
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" data-reactid="11"><div class="ant-select-selection__rendered" data-reactid="12"><div style="display:block;user-select:none;-webkit-user-select:none;" unselectable="unselectable" class="ant-select-selection__placeholder" data-reactid="13">Search Components...</div><ul data-reactid="14"><li class="ant-select-search ant-select-search--inline" data-reactid="15"><div class="ant-select-search__field__wrap" data-reactid="16"><input value="" class="ant-select-search__field" data-reactid="17"/><span class="ant-select-search__field__mirror" data-reactid="18"></span></div></li></ul></div><span class="ant-select-arrow" style="user-select:none;-webkit-user-select:none;" unselectable="unselectable" data-reactid="19"><b data-reactid="20"></b></span></div></div></div><button type="button" class="ant-btn ant-btn-ghost ant-btn-sm lang" data-reactid="21"><span data-reactid="22">中文</span></button><ul class="ant-menu ant-menu-horizontal ant-menu-light ant-menu-root" role="menu" aria-activedescendant="" id="nav" tabindex="0" data-reactid="23"><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="24"><a href="/" data-reactid="25"><span data-reactid="26">Home</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="27"><a href="/docs/spec/introduce" data-reactid="28"><span data-reactid="29">Specification</span></a></li><li class="ant-menu-item-selected ant-menu-item" role="menuitem" aria-selected="true" data-reactid="30"><a href="/docs/react/introduce" data-reactid="31"><span data-reactid="32">Components</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="33"><a href="/docs/pattern/navigation" data-reactid="34"><span data-reactid="35">Pattern</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="36"><a href="/docs/practice/cases" data-reactid="37"><span data-reactid="38">Practice</span></a></li><li class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="39"><a href="/docs/resource/download" data-reactid="40"><span data-reactid="41">Resource</span></a></li></ul></div></div></header><div class="main-wrapper" data-reactid="42"><div class="ant-row" data-reactid="43"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-4" data-reactid="44"><ul class="ant-menu ant-menu-inline aside-container ant-menu-light ant-menu-root" role="menu" aria-activedescendant="" tabindex="0" data-reactid="45"><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="46"><a href="/docs/react/introduce" data-reactid="47">Ant Design of React</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="48"><a href="/docs/react/getting-started" data-reactid="49">Getting Started</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="50"><a href="/docs/react/install" data-reactid="51">Installation</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="52"><a href="/docs/react/practical-projects" data-reactid="53">Real project with dva</a></li><li style="padding-left:24px;" class="ant-menu-item-selected ant-menu-item" role="menuitem" aria-selected="true" data-reactid="54"><a href="/docs/react/use-with-create-react-app" data-reactid="55">Use in create-react-app</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="56"><a href="/docs/react/customize-theme" data-reactid="57">Customize Theme</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="58"><a href="//github.com/ant-design/intl-example" target="_blank" rel="noopener noreferrer" data-reactid="59">i18n Solution</a></li><li style="padding-left:24px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="60"><a href="/changelog" data-reactid="61">Change Log</a></li><li class="ant-menu-submenu-inline ant-menu-submenu-open ant-menu-submenu" data-reactid="62"><div style="padding-left:24px;" class="ant-menu-submenu-title" aria-open="true" aria-owns="1483803681625_12" aria-haspopup="true" data-reactid="63"><h4 data-reactid="64">Components</h4></div><ul class="ant-menu ant-menu-inline ant-menu-sub" role="menu" aria-activedescendant="" id="1483803681625_12" data-reactid="65"><li class=" ant-menu-item-group" data-reactid="66"><div class="ant-menu-item-group-title" data-reactid="67">General</div><ul class="ant-menu-item-group-list" data-reactid="68"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="69"><a href="/components/button/" data-reactid="70"><span data-reactid="71">Button</span><span class="chinese" data-reactid="72"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="73"><a href="/components/icon/" data-reactid="74"><span data-reactid="75">Icon</span><span class="chinese" data-reactid="76"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="77"><div class="ant-menu-item-group-title" data-reactid="78">Layout</div><ul class="ant-menu-item-group-list" data-reactid="79"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="80"><a href="/components/grid/" data-reactid="81"><span data-reactid="82">Grid</span><span class="chinese" data-reactid="83"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="84"><a href="/components/layout/" data-reactid="85"><span data-reactid="86">Layout</span><span class="chinese" data-reactid="87"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="88"><div class="ant-menu-item-group-title" data-reactid="89">Navigation</div><ul class="ant-menu-item-group-list" data-reactid="90"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="91"><a href="/components/affix/" data-reactid="92"><span data-reactid="93">Affix</span><span class="chinese" data-reactid="94"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="95"><a href="/components/back-top/" data-reactid="96"><span data-reactid="97">BackTop</span><span class="chinese" data-reactid="98"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="99"><a href="/components/breadcrumb/" data-reactid="100"><span data-reactid="101">Breadcrumb</span><span class="chinese" data-reactid="102"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="103"><a href="/components/dropdown/" data-reactid="104"><span data-reactid="105">Dropdown</span><span class="chinese" data-reactid="106"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="107"><a href="/components/menu/" data-reactid="108"><span data-reactid="109">Menu</span><span class="chinese" data-reactid="110"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="111"><a href="/components/pagination/" data-reactid="112"><span data-reactid="113">Pagination</span><span class="chinese" data-reactid="114"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="115"><a href="/components/steps/" data-reactid="116"><span data-reactid="117">Steps</span><span class="chinese" data-reactid="118"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="119"><a href="/components/tabs/" data-reactid="120"><span data-reactid="121">Tabs</span><span class="chinese" data-reactid="122"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="123"><div class="ant-menu-item-group-title" data-reactid="124">Data Entry</div><ul class="ant-menu-item-group-list" data-reactid="125"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="126"><a href="/components/auto-complete/" data-reactid="127"><span data-reactid="128">AutoComplete</span><span class="chinese" data-reactid="129"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="130"><a href="/components/checkbox/" data-reactid="131"><span data-reactid="132">Checkbox</span><span class="chinese" data-reactid="133"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="134"><a href="/components/cascader/" data-reactid="135"><span data-reactid="136">Cascader</span><span class="chinese" data-reactid="137"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="138"><a href="/components/date-picker/" data-reactid="139"><span data-reactid="140">DatePicker</span><span class="chinese" data-reactid="141"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="142"><a href="/components/form/" data-reactid="143"><span data-reactid="144">Form</span><span class="chinese" data-reactid="145"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="146"><a href="/components/input/" data-reactid="147"><span data-reactid="148">Input</span><span class="chinese" data-reactid="149"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="150"><a href="/components/input-number/" data-reactid="151"><span data-reactid="152">InputNumber</span><span class="chinese" data-reactid="153"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="154"><a href="/components/mention/" data-reactid="155"><span data-reactid="156">Mention</span><span class="chinese" data-reactid="157"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="158"><a href="/components/radio/" data-reactid="159"><span data-reactid="160">Radio</span><span class="chinese" data-reactid="161"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="162"><a href="/components/rate/" data-reactid="163"><span data-reactid="164">Rate</span><span class="chinese" data-reactid="165"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="166"><a href="/components/select/" data-reactid="167"><span data-reactid="168">Select</span><span class="chinese" data-reactid="169"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="170"><a href="/components/slider/" data-reactid="171"><span data-reactid="172">Slider</span><span class="chinese" data-reactid="173"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="174"><a href="/components/switch/" data-reactid="175"><span data-reactid="176">Switch</span><span class="chinese" data-reactid="177"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="178"><a href="/components/time-picker/" data-reactid="179"><span data-reactid="180">TimePicker</span><span class="chinese" data-reactid="181"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="182"><a href="/components/transfer/" data-reactid="183"><span data-reactid="184">Transfer</span><span class="chinese" data-reactid="185"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="186"><a href="/components/tree-select/" data-reactid="187"><span data-reactid="188">TreeSelect</span><span class="chinese" data-reactid="189"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="190"><a href="/components/upload/" data-reactid="191"><span data-reactid="192">Upload</span><span class="chinese" data-reactid="193"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="194"><div class="ant-menu-item-group-title" data-reactid="195">Data Display</div><ul class="ant-menu-item-group-list" data-reactid="196"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="197"><a href="/components/badge/" data-reactid="198"><span data-reactid="199">Badge</span><span class="chinese" data-reactid="200"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="201"><a href="/components/card/" data-reactid="202"><span data-reactid="203">Card</span><span class="chinese" data-reactid="204"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="205"><a href="/components/carousel/" data-reactid="206"><span data-reactid="207">Carousel</span><span class="chinese" data-reactid="208"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="209"><a href="/components/collapse/" data-reactid="210"><span data-reactid="211">Collapse</span><span class="chinese" data-reactid="212"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="213"><a href="/components/calendar/" data-reactid="214"><span data-reactid="215">Calendar</span><span class="chinese" data-reactid="216"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="217"><a href="/components/popover/" data-reactid="218"><span data-reactid="219">Popover</span><span class="chinese" data-reactid="220"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="221"><a href="/components/table/" data-reactid="222"><span data-reactid="223">Table</span><span class="chinese" data-reactid="224"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="225"><a href="/components/tag/" data-reactid="226"><span data-reactid="227">Tag</span><span class="chinese" data-reactid="228"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="229"><a href="/components/timeline/" data-reactid="230"><span data-reactid="231">Timeline</span><span class="chinese" data-reactid="232"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="233"><a href="/components/tooltip/" data-reactid="234"><span data-reactid="235">Tooltip</span><span class="chinese" data-reactid="236"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="237"><a href="/components/tree/" data-reactid="238"><span data-reactid="239">Tree</span><span class="chinese" data-reactid="240"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="241"><div class="ant-menu-item-group-title" data-reactid="242">Feedback</div><ul class="ant-menu-item-group-list" data-reactid="243"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="244"><a href="/components/alert/" data-reactid="245"><span data-reactid="246">Alert</span><span class="chinese" data-reactid="247"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="248"><a href="/components/message/" data-reactid="249"><span data-reactid="250">Message</span><span class="chinese" data-reactid="251"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="252"><a href="/components/modal/" data-reactid="253"><span data-reactid="254">Modal</span><span class="chinese" data-reactid="255"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="256"><a href="/components/notification/" data-reactid="257"><span data-reactid="258">Notification</span><span class="chinese" data-reactid="259"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="260"><a href="/components/popconfirm/" data-reactid="261"><span data-reactid="262">Popconfirm</span><span class="chinese" data-reactid="263"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="264"><a href="/components/progress/" data-reactid="265"><span data-reactid="266">Progress</span><span class="chinese" data-reactid="267"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="268"><a href="/components/spin/" data-reactid="269"><span data-reactid="270">Spin</span><span class="chinese" data-reactid="271"></span></a></li></ul></li><li class=" ant-menu-item-group" data-reactid="272"><div class="ant-menu-item-group-title" data-reactid="273">Other</div><ul class="ant-menu-item-group-list" data-reactid="274"><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="275"><a href="/components/anchor/" data-reactid="276"><span data-reactid="277">Anchor</span><span class="chinese" data-reactid="278"></span></a></li><li style="padding-left:48px;" class="ant-menu-item" role="menuitem" aria-selected="false" data-reactid="279"><a href="/components/locale-provider/" data-reactid="280"><span data-reactid="281">LocaleProvider</span><span class="chinese" data-reactid="282"></span></a></li></ul></li></ul></li></ul></div><div class="main-container ant-col-xs-24 ant-col-sm-24 ant-col-md-18 ant-col-lg-20" data-reactid="283"><article class="markdown" data-reactid="284"><h1 data-reactid="285"><!-- react-text: 286 -->Use in create-react-app<!-- /react-text --><a class="edit-button" href="https://github.com/ant-design/ant-design/blob/master/docs/react/use-with-create-react-app.en-US.md" data-reactid="287"><i class="anticon anticon-edit" data-reactid="288"></i></a></h1><section class="markdown" data-reactid="289"><p data-reactid="290"><a href="https://github.com/facebookincubator/create-react-app" data-reactid="291"><!-- react-text: 292 -->create-react-app<!-- /react-text --></a><!-- react-text: 293 --> is one of best React application development tool, we are going to use <!-- /react-text --><code data-reactid="294"><!-- react-text: 295 -->antd<!-- /react-text --></code><!-- react-text: 296 --> within it and modify the webpack config for some customized needs.<!-- /react-text --></p></section><section class="toc" data-reactid="297"><ul data-reactid="298"><li data-reactid="299"><a class="bisheng-toc-h2" href="#Install-and-Initialization" data-reactid="300"><!-- react-text: 301 -->Install and Initialization<!-- /react-text --></a></li><li data-reactid="302"><a class="bisheng-toc-h2" href="#Import-antd" data-reactid="303"><!-- react-text: 304 -->Import antd<!-- /react-text --></a></li><li data-reactid="305"><a class="bisheng-toc-h2" href="#Advanced-Guides" data-reactid="306"><!-- react-text: 307 -->Advanced Guides<!-- /react-text --></a></li></ul></section><section class="markdown" data-reactid="308"><h2 id="Install-and-Initialization" data-reactid="309"><span data-reactid="310"><!-- react-text: 311 -->Install and Initialization<!-- /react-text --></span><a href="#Install-and-Initialization" class="anchor" data-reactid="312">#</a></h2><p data-reactid="313"><!-- react-text: 314 -->We need to install <!-- /react-text --><code data-reactid="315"><!-- react-text: 316 -->create-react-app<!-- /react-text --></code><!-- react-text: 317 --> first.<!-- /react-text --></p><pre class="language-bash" data-reactid="318"><code data-reactid="319">$ <span class="token function">npm</span> <span class="token function">install</span> -g create-react-app</code></pre><p data-reactid="320"><!-- react-text: 321 -->Create a new project named <!-- /react-text --><code data-reactid="322"><!-- react-text: 323 -->antd-demo<!-- /react-text --></code><!-- react-text: 324 -->.<!-- /react-text --></p><pre class="language-bash" data-reactid="325"><code data-reactid="326">$ USE_YARN<span class="token operator">=</span>no create-react-app antd-demo</code></pre><p data-reactid="327"><!-- react-text: 328 -->The tool will create and initialize environment and dependencies automaticly,
please try config your proxy setting or use other npm registry if any network errors happen during it.<!-- /react-text --></p><p data-reactid="329"><!-- react-text: 330 -->Then we go inside <!-- /react-text --><code data-reactid="331"><!-- react-text: 332 -->antd-demo<!-- /react-text --></code><!-- react-text: 333 --> and start it.<!-- /react-text --></p><pre class="language-bash" data-reactid="334"><code data-reactid="335">$ <span class="token function">cd</span> antd-demo
$ <span class="token function">npm</span> start</code></pre><p data-reactid="336"><!-- react-text: 337 -->Open browser at <!-- /react-text --><a href="http://localhost:3000/" data-reactid="338"><!-- react-text: 339 -->http://localhost:3000/<!-- /react-text --></a><!-- react-text: 340 -->, it renders a header saying &quot;Welcome to React&quot; on the page.<!-- /react-text --></p><h2 id="Import-antd" data-reactid="341"><span data-reactid="342"><!-- react-text: 343 -->Import antd<!-- /react-text --></span><a href="#Import-antd" class="anchor" data-reactid="344">#</a></h2><p data-reactid="345"><!-- react-text: 346 -->It is the default directory structure below.<!-- /react-text --></p><pre class="language-null" data-reactid="347"><code data-reactid="348">├── README<span class="token punctuation">.</span>md
├── package<span class="token punctuation">.</span>json
├── public
│ ├── favicon<span class="token punctuation">.</span>ico
│ └── index<span class="token punctuation">.</span>html
├── src
│ ├── App<span class="token punctuation">.</span>css
│ ├── App<span class="token punctuation">.</span>js
│ ├── App<span class="token punctuation">.</span>test<span class="token punctuation">.</span>js
│ ├── index<span class="token punctuation">.</span>css
│ ├── index<span class="token punctuation">.</span>js
│ └── logo<span class="token punctuation">.</span>svg
└── yarn<span class="token punctuation">.</span>lock</code></pre><p data-reactid="349"><!-- react-text: 350 -->Now we install <!-- /react-text --><code data-reactid="351"><!-- react-text: 352 -->antd<!-- /react-text --></code><!-- react-text: 353 --> from npm.<!-- /react-text --></p><pre class="language-bash" data-reactid="354"><code data-reactid="355">$ <span class="token function">npm</span> <span class="token function">install</span> antd --save</code></pre><p data-reactid="356"><!-- react-text: 357 -->Modify <!-- /react-text --><code data-reactid="358"><!-- react-text: 359 -->src/App.js<!-- /react-text --></code><!-- react-text: 360 -->, import Button component from <!-- /react-text --><code data-reactid="361"><!-- react-text: 362 -->antd<!-- /react-text --></code><!-- react-text: 363 -->.<!-- /react-text --></p><pre class="language-jsx" data-reactid="364"><code data-reactid="365"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span> Component <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> Button <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'antd'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">'./App.css'</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">App</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
<span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token punctuation">(</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>App<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Button<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Button</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> App<span class="token punctuation">;</span></code></pre><p data-reactid="366"><!-- react-text: 367 -->Add <!-- /react-text --><code data-reactid="368"><!-- react-text: 369 -->antd/dist/antd.css<!-- /react-text --></code><!-- react-text: 370 --> at the top of <!-- /react-text --><code data-reactid="371"><!-- react-text: 372 -->src/App.css<!-- /react-text --></code><!-- react-text: 373 -->.<!-- /react-text --></p><pre class="language-css" data-reactid="374"><code data-reactid="375"><span class="token atrule"><span class="token rule">@import</span> <span class="token string">'~antd/dist/antd.css'</span><span class="token punctuation">;</span></span>
<span class="token selector"><span class="token class">.App</span> </span><span class="token punctuation">{</span>
<span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token number">...</span></code></pre><p data-reactid="376"><!-- react-text: 377 -->Ok, you now see a blue primary button displaying in page now, next you can choose any components of <!-- /react-text --><code data-reactid="378"><!-- react-text: 379 -->antd<!-- /react-text --></code><!-- react-text: 380 --> to develop your application. Visit other workflow of <!-- /react-text --><code data-reactid="381"><!-- react-text: 382 -->create-react-app<!-- /react-text --></code><!-- react-text: 383 --> at its <!-- /react-text --><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md" data-reactid="384"><!-- react-text: 385 -->User Guide <!-- /react-text --></a><!-- react-text: 386 -->.<!-- /react-text --></p><h2 id="Advanced-Guides" data-reactid="387"><span data-reactid="388"><!-- react-text: 389 -->Advanced Guides<!-- /react-text --></span><a href="#Advanced-Guides" class="anchor" data-reactid="390">#</a></h2><p data-reactid="391"><!-- react-text: 392 -->We are successd to run antd components now, but in the real world, there are still lots of problems about antd-demo.
For instance, we actully import all components in the project which will be a serious network perfermance issue.<!-- /react-text --></p><blockquote data-reactid="393"><p data-reactid="394"><!-- react-text: 395 -->You will see a warning in your browser console.
<!-- /react-text --><img src="https://zos.alipayobjects.com/rmsportal/vgcHJRVZFmPjAawwVoXK.png" data-reactid="396"/></p></blockquote><p data-reactid="397"><!-- react-text: 398 -->So it is necessary to customize the default webpack config. We can achieve that by using <!-- /react-text --><code data-reactid="399"><!-- react-text: 400 -->eject<!-- /react-text --></code><!-- react-text: 401 --> script command.<!-- /react-text --></p><pre class="language-bash" data-reactid="402"><code data-reactid="403">$ <span class="token function">npm</span> run <span class="token function">eject</span></code></pre><h3 id="Import-on-demand" data-reactid="404"><span data-reactid="405"><!-- react-text: 406 -->Import on demand<!-- /react-text --></span><a href="#Import-on-demand" class="anchor" data-reactid="407">#</a></h3><p data-reactid="408"><a href="https://github.com/ant-design/babel-plugin-import" data-reactid="409"><!-- react-text: 410 -->babel-plugin-import<!-- /react-text --></a><!-- react-text: 411 --> is a babel plugin for importing components on demand (<!-- /react-text --><a href="/docs/react/getting-started-cn#按需加载" data-reactid="412">principle</a><!-- react-text: 413 -->). After eject all config files to antd-demo, we allowed to install it and modify <!-- /react-text --><code data-reactid="414"><!-- react-text: 415 -->config/webpack.config.dev.js<!-- /react-text --></code><!-- react-text: 416 --> now.<!-- /react-text --></p><pre class="language-bash" data-reactid="417"><code data-reactid="418">$ <span class="token function">npm</span> <span class="token function">install</span> babel-plugin-import --save-dev</code></pre><pre class="language-diff" data-reactid="419"><code data-reactid="420">// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
<span class="token inserted">+ plugins: [</span>
<span class="token inserted">+ ['import', [{ libraryName: "antd", style: 'css' }]],</span>
<span class="token inserted">+ ],</span>
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true
}
},</code></pre><blockquote data-reactid="421"><p data-reactid="422"><!-- react-text: 423 -->Note: because there is no <!-- /react-text --><code data-reactid="424"><!-- react-text: 425 -->.babelrc<!-- /react-text --></code><!-- react-text: 426 --> file after config eject, so we have to put the babel option into <!-- /react-text --><code data-reactid="427"><!-- react-text: 428 -->webpack.config.js<!-- /react-text --></code><!-- react-text: 429 --> or <!-- /react-text --><code data-reactid="430"><!-- react-text: 431 -->babel<!-- /react-text --></code><!-- react-text: 432 --> field of <!-- /react-text --><code data-reactid="433"><!-- react-text: 434 -->package.json<!-- /react-text --></code><!-- react-text: 435 -->.<!-- /react-text --></p></blockquote><p data-reactid="436"><!-- react-text: 437 -->Remove the <!-- /react-text --><code data-reactid="438"><!-- react-text: 439 -->@import &#x27;~antd/dist/antd.css&#x27;;<!-- /react-text --></code><!-- react-text: 440 --> statement added before because <!-- /react-text --><code data-reactid="441"><!-- react-text: 442 -->babel-plugin-import<!-- /react-text --></code><!-- react-text: 443 --> will import styles.<!-- /react-text --></p><p data-reactid="444"><!-- react-text: 445 -->Then reboot <!-- /react-text --><code data-reactid="446"><!-- react-text: 447 -->npm start<!-- /react-text --></code><!-- react-text: 448 --> and visit demo page, you should find that the above warning message would be gone which prove the <!-- /react-text --><code data-reactid="449"><!-- react-text: 450 -->import on demand<!-- /react-text --></code><!-- react-text: 451 --> config is effective now.<!-- /react-text --></p><h3 id="Customize-Theme" data-reactid="452"><span data-reactid="453"><!-- react-text: 454 -->Customize Theme<!-- /react-text --></span><a href="#Customize-Theme" class="anchor" data-reactid="455">#</a></h3><p data-reactid="456"><!-- react-text: 457 -->According to <!-- /react-text --><a href="/docs/react/customize-theme" data-reactid="458">Customize Theme documentation</a><!-- react-text: 459 -->, we need <!-- /react-text --><code data-reactid="460"><!-- react-text: 461 -->less<!-- /react-text --></code><!-- react-text: 462 --> variables modify ability of <!-- /react-text --><a href="https://github.com/webpack/less-loader" data-reactid="463"><!-- react-text: 464 -->less-loader<!-- /react-text --></a><!-- react-text: 465 -->, so we add it.<!-- /react-text --></p><pre class="language-bash" data-reactid="466"><code data-reactid="467">$ <span class="token function">npm</span> <span class="token function">install</span> <span class="token function">less</span> less-loader --save-dev</code></pre><pre class="language-diff" data-reactid="468"><code data-reactid="469">loaders: [
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
<span class="token inserted">+ /\.less$/,</span>
/\.css$/,
/\.json$/,
/\.svg$/
],
loader: 'url',
},
...
// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
plugins: [
<span class="token deleted">- ['import', [{ libraryName: "antd", style: 'css' }]],</span>
<span class="token inserted">+ ['import', [{ libraryName: "antd", style: true }]], // import less</span>
],
},
...
<span class="token inserted">+ // Parse less files and modify variables</span>
<span class="token inserted">+ {</span>
<span class="token inserted">+ test: /\.less$/,</span>
<span class="token inserted">+ loader: 'style!css!postcss!less?{modifyVars:{"@primary-color":"#1DA57A"}}'</span>
<span class="token inserted">+ },</span>
]</code></pre><p data-reactid="470"><!-- react-text: 471 -->We use <!-- /react-text --><code data-reactid="472"><!-- react-text: 473 -->modifyVars<!-- /react-text --></code><!-- react-text: 474 --> option of <!-- /react-text --><a href="https://github.com/webpack/less-loader#less-options" data-reactid="475"><!-- react-text: 476 -->less-loader<!-- /react-text --></a><!-- react-text: 477 --> here, you can see a green button rendered on the page after reboot start server.<!-- /react-text --></p><hr data-reactid="478"/><p data-reactid="479"><!-- react-text: 480 -->Finally, we use antd with create-react-app successfully, you can learn these practice for your own webpack workflow too, and find more webpack config in the <!-- /react-text --><a href="https://github.com/ant-tool/atool-build/blob/master/src/getWebpackCommonConfig.js" data-reactid="481"><!-- react-text: 482 -->atool-build<!-- /react-text --></a><!-- react-text: 483 -->. (For instance, add <!-- /react-text --><a href="https://github.com/ant-tool/atool-build/blob/e4bd2959689b6a95cb5c1c854a5db8c98676bdb3/src/getWebpackCommonConfig.js#L90" data-reactid="484"><!-- react-text: 485 -->moment noParse<!-- /react-text --></a><!-- react-text: 486 --> to avoid loading all language files)<!-- /react-text --></p><p data-reactid="487"><!-- react-text: 488 -->Source code about this article<!-- /react-text --><a href="https://github.com/ant-design/create-react-app-antd" data-reactid="489"><!-- react-text: 490 -->https://github.com/ant-design/create-react-app-antd<!-- /react-text --></a></p></section></article></div></div><div class="ant-row" data-reactid="491"><div class="ant-col-xs-24 ant-col-sm-24 ant-col-md-18 ant-col-md-offset-6 ant-col-lg-20 ant-col-lg-offset-4" data-reactid="492"><section class="prev-next-nav" data-reactid="493"><a class="prev-page" href="/docs/react/practical-projects" data-reactid="494">Real project with dva</a><a class="next-page" href="/docs/react/customize-theme" data-reactid="495">Customize Theme</a></section></div></div></div><footer id="footer" data-reactid="496"><ul data-reactid="497"><li data-reactid="498"><h2 data-reactid="499">GitHub</h2><div data-reactid="500"><a target="_blank " href="https://github.com/ant-design/ant-design" data-reactid="501"><span data-reactid="502">Repository</span></a></div><div data-reactid="503"><a target="_blank" rel="noopener noreferrer" href="https://github.com/dvajs/dva" data-reactid="504">dva</a><!-- react-text: 505 --> - <!-- /react-text --><span data-reactid="506">Framework</span></div><div data-reactid="507"><a target="_blank" rel="noopener noreferrer" href="https://github.com/dvajs/dva-cli" data-reactid="508">dva-cli</a><!-- react-text: 509 --> -<!-- /react-text --><span data-reactid="510">Scaffold</span></div><div data-reactid="511"><a target="_blank" rel="noopener noreferrer" href="http://ant-tool.github.io" data-reactid="512">ant-tool</a><!-- react-text: 513 --> - <!-- /react-text --><span data-reactid="514">Developer Tools</span></div></li><li data-reactid="515"><h2 data-reactid="516"><span data-reactid="517">Links</span></h2><div data-reactid="518"><a href="http://mobile.ant.design" data-reactid="519">Ant Design Mobile</a><span data-reactid="520"> - </span><span data-reactid="521">Mobile</span></div><div data-reactid="522"><a href="https://g2.alipay.com/" data-reactid="523">G2</a><span data-reactid="524"> - </span><span data-reactid="525">Data Visualization</span></div><div data-reactid="526"><a href="https://antv.alipay.com/" data-reactid="527">AntV</a><span data-reactid="528"> - </span><span data-reactid="529">Data Visualization Specification</span></div><div data-reactid="530"><a href="http://motion.ant.design" data-reactid="531">Ant Motion</a><span data-reactid="532"> - </span><span data-reactid="533">Motion</span></div><div data-reactid="534"><a href="http://library.ant.design/" data-reactid="535">AntD Library</a><span data-reactid="536"> - </span><span data-reactid="537">Axure library of Ant Design</span></div><div data-reactid="538"><a href="http://ux.ant.design" data-reactid="539">Ant UX</a><span data-reactid="540"> - </span><span data-reactid="541">Sitemap Template</span></div></li><li data-reactid="542"><h2 data-reactid="543"><span data-reactid="544">Community</span></h2><div data-reactid="545"><a rel="noopener noreferrer" href="/changelog" data-reactid="546"><span data-reactid="547">Change Log</span></a></div><div data-reactid="548"><a target="_blank" rel="noopener noreferrer" href="https://github.com/ant-design/ant-design/issues" data-reactid="549"><span data-reactid="550">Feedback</span></a></div><div data-reactid="551"><a target="_blank" rel="noopener noreferrer" href="https://gitter.im/ant-design/ant-design" data-reactid="552"><span data-reactid="553">Chat Room</span></a></div><div data-reactid="554"><a target="_blank" rel="noopener noreferrer" href="https://github.com/ant-design/ant-design/issues/new" data-reactid="555"><span data-reactid="556">Bug Report</span></a></div></li><li data-reactid="557"><div data-reactid="558"><!-- react-text: 559 -->©2016 <!-- /react-text --><span data-reactid="560">Created by Ant UED</span></div><div data-reactid="561"><!-- react-text: 562 -->Powered by <!-- /react-text --><a href="https://github.com/benjycui/bisheng" data-reactid="563">BiSheng</a></div><div style="margin-top:10px;" data-reactid="564"><span data-reactid="565">Version: </span><div class="ant-select-sm ant-select ant-select-enabled" data-reactid="566"><div class="ant-select-selection
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0" data-reactid="567"><div class="ant-select-selection__rendered" data-reactid="568"><div class="ant-select-selection-selected-value" title="1.11.4" style="display:block;opacity:1;" data-reactid="569">1.11.4</div></div><span class="ant-select-arrow" style="user-select:none;-webkit-user-select:none;" unselectable="unselectable" data-reactid="570"><b data-reactid="571"></b></span></div></div></div></li></ul></footer></div>
</div>
<script>
function isZhCN(pathname) {
return /-cn\/?$/.test(pathname);
}
function getLocalizedPathname(path, zhCN) {
var pathname = path.startsWith('/') ? path : '/' + path;
if (!zhCN) { // to enUS
return /\/?index-cn/.test(pathname) ? '/' : pathname.replace('-cn', '');
} else if (pathname === '/') {
return '/index-cn';
} else if (pathname.endsWith('/')) {
return pathname.replace(/\/$/, '-cn/');
}
return pathname + '-cn';
}
var queryString = location.search;
if (queryString) {
var pathname = location.pathname;
var isZhCNConfig = queryString.indexOf('zh-CN') > -1;
if (isZhCNConfig !== isZhCN(pathname)) {
location.pathname = getLocalizedPathname(pathname, isZhCNConfig)
}
}
</script>
<script src="/common.js"></script>
<script src="/index.js"></script>
</body>
</html>