Git Product home page Git Product logo

Comments (4)

michabu avatar michabu commented on August 18, 2024 1

Thank you @wmonk for the answer. In the meantime I managed to rename everything in my project to .ts / .tsx and types. Since my project was not to big yet that was doable.

As I understand it the option allowJs=true in tsconfig.json should theoretically allow to just "do a quick sanity check" on .js files and otherwise pass them through to the output folder to allow for a smooth transition. It didn't work for me though. But wouldn't that theoretically be an option for people wanting to add the benefits of typescript without the pain of having to rename / add types to everything in an existing project?

After all it is a great addition (imho) to have the types around. It already helped me catch and understand a couple of issues with my code.

Thanks again @wmonk for making using ts with react-scripts possible.

from create-react-app-typescript.

wmonk avatar wmonk commented on August 18, 2024

Hi @michabu, no problem 😄 !

You are correct, react-scripts-ts will not compile js or jsx files. You can see in this commit that babel-loader was removed from the webpack config. You are still able to require js files, but they will not be run through babel. I suppose the reason for this is to keep the package as slim as possible, if you're writing typescript, it's unlikely you need the babel transpiler as well. I think CRA promotes starting new projects, rather than retrofitting into old projects.

If you want to add back in the babel loader, you can run npm run eject, and then update the webpack config yourself. Be warned, this is a permanent action! However, you could do something clever with git, wherein you eject, update the config, and commit in one go. Then to use react-scripts-ts again in the future, you could revert that commit. I've not tried this myself, and is only a thought, so take it with a pinch of salt 😄

from create-react-app-typescript.

wmonk avatar wmonk commented on August 18, 2024

@michabu, glad you got it sorted! Not sure about getting it to work incrementally, I suppose updating the webpack config should be enough though.

from create-react-app-typescript.

sandys avatar sandys commented on August 18, 2024

@wmonk sorry for commenting on an old bug, but i didnt want to create a new one. we are looking at migrating a big jsx project to tsx as well. and we would love to use your infrastructure. is it not possible to have babel as an optional dependency (or some other way to run jsx ) ?

having a large single cutover is going to be extremely hard for a lot of projects like us.

from create-react-app-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.