react-workspaces / react-workspaces-playground

βš›οΈ 🐈 Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
https://react-workspaces.github.io/react-workspaces-playground/
764 stars 128 forks source link

πŸŽ„πŸŽ React App Rewired, Ant-Design & TypeScript #21

Closed F1LT3R closed 4 years ago

F1LT3R commented 4 years ago

πŸŽ„πŸŽ React App Rewired, Ant-Design & TypeScript

Includes examples apps for Ant-Design and TypeScript.

About

This PR demonstrates React-App-Rewired compatibility as well as basic usage of Ant Design and TypeScript examples.

This PR relates to: https://github.com/react-workspaces/react-workspaces-playground/issues/9

Questions for Review

  1. [ ] Does the configuration on the branch ant-design-compat work for others?
  2. [ ] Should I fold the Ant Design + React-App-Rewired example into this library? (I'm thinking "yes").
  3. [ ] Can anyone please test other React-App-Rewired configurations and let me know if they work?
  4. [ ] Can someone verify they can yarn test and yarn lint each package, as well as yarn test from the root (which lints and provides coverage. I have checked these but it would be nice to get another pair of eyes on this. πŸ‘€

Issues Addressed By This PR

Technical Details

Ant/Rewired Demo Configuration

package.json

The packages/apps/app-ant-design-rewired/package.json file was updated. Dependencies were added to allow React-App-Rewired inject a custom configuration into react-scripts allowing the setup of Ant Design with babel-plugin-export for automated style importing.

The package start script was updated to use react-app-rewired with the "--scripts-version" of @reacect-workspaces-playground/react-scripts. This allows R.A.R. to use the Yarn Workspaces configuration as the base WebPack config for overriding.

{
    "dependencies": {
        "antd": "^3.26.4",
        "babel-plugin-import": "^1.13.0",
        "customize-cra": "^0.9.1",
        "react-app-rewired": "^2.1.5"
  },
    "scripts": {
        "start": "react-app-rewired start --scripts-version @react-workspaces/react-scripts"
    }
}

config-overrides.js

The config-overrides.js file was added to use the Babel Importer to automatically load the associated styles of an Ant Design component.

// packages/apps/app-ant-design-rewired/config-overrides.js
const {override, fixBabelImports} = require('customize-cra');

module.exports = override(
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: 'css'
    })
);

App.js

The packages/apps/app-ant-design-rewired/src/App.js file was updated to include the Ant Design <DatePicker /> component.

...
import {DatePicker} from 'antd';

class App extends Component {
    render() {
        return (
            <div className="App">
...
                    <div className="components">
                        <CompOne />
                        <CompTwo />
                        <DatePicker />
                    </div>
...
            </div>
        );
    }
}

export default App;

Ant-Design Screenshot

Google Chrome 2019-12-26 at 16 17 02@2x

TypeScript Screenshot

Google Chrome 2019-12-26 at 16 18 01@2x

Happy Holidays! πŸŒŸπŸ‘πŸ‘‘πŸ‘ΌπŸŽ„πŸŽπŸŽ…πŸͺπŸ₯›πŸ•Žβ­πŸŒ™πŸ•―οΈβ˜ƒοΈ ❄️ θ‡˜ε…«

cipriancaba commented 4 years ago

Looks awesome.. Only thing that's missing seems to be typescript project references.. Any plan to add that?

F1LT3R commented 4 years ago

@cipriancaba TypeScript project references? Forgive me, I am not sure what you mean.

F1LT3R commented 4 years ago

Only thing that's missing seems to be typescript project references - @cipriancaba

Ah... you must mean this?

https://www.typescriptlang.org/docs/handbook/project-references.html

Are you thinking it should be added in app-typescript, or in the storybook-typescript or both?

I'm trying to stick to the Create-React-App's TypeScript template as much as possible. Is there a really good reason to change it?

I'm not a TypeScript user, so project references are not something I understand.

Perhaps some other experienced React+TypeScript devs can weigh in on this?