proComponent组件默认是 *.ts后缀
支持 js项目,缺点:不能自动的引入样式,ts项目没有这个问题

install

  1. yarn add @ant-design/pro-form @ant-design/pro-layout @ant-design/pro-list @ant-design/pro-descriptions @ant-design/pro-card @ant-design/pro-skeleton @ant-design/pro-table

如果项目使用 less会自动引入主题,解决下面的报错,会自动加载 css
需要自己手动的引入 proComponent 的样式
以 proCard组件为例,手动引入css文件 import '@ant-design/pro-card/dist/card.css'

  1. import React from 'react';
  2. import ProCard from '@ant-design/pro-card';
  3. import '@ant-design/pro-card/dist/card.css';
  4. import styles from './App.module.less';
  5. function App() {
  6. return (
  7. <ProCard title="左右分栏带标题" extra="2019年9月28日" split="vertical" bordered headerBordered>
  8. <ProCard title="左侧详情" colSpan="300px">
  9. 左侧内容
  10. </ProCard>
  11. <ProCard title="流量占用情况">
  12. <div style={{ height: 360 }}>右侧内容</div>
  13. </ProCard>
  14. </ProCard>
  15. );
  16. }
  17. export default App;

less报错

// https://github.com/ant-design/ant-motion/issues/44
.bezierEasingMixin();
Inline JavaScript is not enabled. Is it set in your options?
image.png
解决:修改 config/webpack.config.js,找到 if (preProcessor) 新增 lessOption

  1. if (preProcessor) {
  2. let lessOption = {}
  3. if(preProcessor === 'less-loader') {
  4. lessOption = {
  5. javascriptEnabled: true,
  6. modifyVars: {
  7. 'primary-color': '#ff4757',
  8. 'link-color': '#ff4757',
  9. }
  10. }
  11. loaders.push(
  12. {
  13. loader: require.resolve('resolve-url-loader'),
  14. options: {
  15. sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
  16. root: paths.appSrc,
  17. },
  18. },
  19. {
  20. loader: require.resolve(preProcessor),
  21. options: {
  22. sourceMap: true,
  23. ...lessOption
  24. },
  25. }
  26. );
  27. }
  28. return loaders;
  29. }