react-starter-kit icon indicating copy to clipboard operation
react-starter-kit copied to clipboard

how to support antd render in server?

Open TristanDongMaster opened this issue 7 years ago • 4 comments

I follow the steps to import antd, it works 687474703a2f2f672e7265636f726469742e636f2f466177325941573759552e676966 , but the page only load the antd css after page rendered, so the page is ugly in the first page render: https://github.com/ant-design/react-starter-kit; here is the config: // Only use babel-plugin-import in client side clientConfig.module.rules[0].options.plugins = [ ...clientConfig.module.rules[0].options.plugins, ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true, }] ];

TristanDongMaster avatar Dec 06 '18 06:12 TristanDongMaster

I also firs a issues in antd github:https://github.com/ant-design/ant-design/issues/13458

TristanDongMaster avatar Dec 06 '18 06:12 TristanDongMaster

@TristanDongMaster you can check my branch

import React from 'react';
// Import component
import { Menu, Icon } from 'antd';
// Import styles - whole styles, you can also import some special style for this
import s from 'antd/dist/antd.min.css';
import withStyles from 'isomorphic-style-loader/lib/withStyles';

const { SubMenu } = Menu;
const MenuItemGroup = Menu.ItemGroup;

class App extends React.Component {
  state = {
    current: 'mail',
  };

  handleClick = e => {
    console.log('click ', e);
    this.setState({
      current: e.key,
    });
  };

  render() {
    return (
      <Menu
        onClick={this.handleClick}
        selectedKeys={[this.state.current]}
        mode="horizontal"
      >
        <Menu.Item key="mail">
          <Icon type="mail" />
          Navigation One
        </Menu.Item>
        <Menu.Item key="app" disabled>
          <Icon type="appstore" />
          Navigation Two
        </Menu.Item>
        <SubMenu
          title={
            <span className="submenu-title-wrapper">
              <Icon type="setting" />
              Navigation Three - Submenu
            </span>
          }
        >
          <MenuItemGroup title="Item 1">
            <Menu.Item key="setting:1">Option 1</Menu.Item>
            <Menu.Item key="setting:2">Option 2</Menu.Item>
          </MenuItemGroup>
          <MenuItemGroup title="Item 2">
            <Menu.Item key="setting:3">Option 3</Menu.Item>
            <Menu.Item key="setting:4">Option 4</Menu.Item>
          </MenuItemGroup>
        </SubMenu>
        <Menu.Item key="alipay">
          <a
            href="https://ant.design"
            target="_blank"
            rel="noopener noreferrer"
          >
            Navigation Four - Link
          </a>
        </Menu.Item>
      </Menu>
    );
  }
}

// Pass you style to withStyles function
export default withStyles(s)(App);

Hope it will help

mmarkelov avatar Dec 08 '18 16:12 mmarkelov

@mmarkelov even if I try to do with isomorphic-style-loader I am getting below isse

\node_modules\antd\lib\style\index.css:6
@font-face {
^
SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Module._extensions..js (module.js:664:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Work\_DEV_IDEAPORTAL\ideaportal\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

vamsi981 avatar Jan 13 '19 07:01 vamsi981

Thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.

NOTE: The main branch has been updated with React Starter Kit v2, using JAM-style architecture.

ulani avatar May 27 '21 21:05 ulani