babel-plugin-typescript-to-proptypes icon indicating copy to clipboard operation
babel-plugin-typescript-to-proptypes copied to clipboard

Making it work with `create-react-app --template typscript`

Open Sourav12061999 opened this issue 2 years ago • 1 comments

I want some help on how to set this up with the `create-react-app --template typescript, I am not sure I am doing something wrong or it's some issue from the package itself

Sourav12061999 avatar Feb 23 '23 12:02 Sourav12061999

Hello, I believe the following should work:

  1. Eject CRA (to gain access to babel config)
  2. Install babel-plugin-typescript-to-proptypes
  3. Create a babel.config.js file, that contains the babel settings from the Readme.md file.
  4. Remove babel settings from package.json
  5. Change process.env.BABEL_ENV to "development" in scripts/build.js, otherwise the proptypes are removed in prod mode
  6. Add import React from "react"; to each component, even if it is not needed anymore when using the new JSX transform. Otherwise the proptypes won't be exported (see https://github.com/milesj/babel-plugin-typescript-to-proptypes/issues/64)
  7. Runnpm run build. Proptypes should still be in the compiled files in build/static/js/*.js

maurer2 avatar May 31 '23 13:05 maurer2