Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to Typescript #979

Closed
krazyjakee opened this issue Apr 14, 2019 · 3 comments
Closed

Migrating to Typescript #979

krazyjakee opened this issue Apr 14, 2019 · 3 comments

Comments

@krazyjakee
Copy link

I have a large project and wish to start migrating to Typescript one component at a time.

I have tried --with-typescript but that requires me to rename all files at once. I would like to convert slowly ensuring that unconverted files keep their initial extension while new files adopt typescript file extensions.

How do I go about this in razzle?

@frosato-dev
Copy link

Hey, I'm also facing a hard time trying to make the with-typescript example work with jsx files to allow progressive migration of existing projects.
Does anyone have an idea of how to archive this goal ?

@krazyjakee
Copy link
Author

krazyjakee commented Apr 24, 2019

Figured it out!

npm i -D @babel/preset-typescript ts-loader typescript

Add @babel/typescript to .babelrc

"presets": [
    "razzle/babel",
    "@babel/typescript"
]

Add this to razzle.config.js

config.resolve.extensions = config.resolve.extensions.concat(['.ts', '.tsx']);
config.module.rules.push({ test: /\.tsx?$/, loader: 'ts-loader' });

Create a tsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        // Target latest version of ECMAScript.
        "target": "esnext",
        // Search under node_modules for non-relative imports.
        "moduleResolution": "node",
        // Process & infer types from .js files.
        "allowJs": false,
        // Enable strictest settings like strictNullChecks & noImplicitAny.
        "strict": false,
        // Disallow features that require cross-file information for emit.
        "isolatedModules": true,
        // Import non-ES modules as default imports.
        "esModuleInterop": true,
        "jsx": "react"
    },
    "include": [
        "src"
    ],
    "exclude": [
        "node_modules",
    ]
}

That's it, now you can rename extensions to .ts and .tsx to enable typescript for those files.

@inkblotty
Copy link

If you're coming here from the future, checkout the great razzle-supported typescript plugin here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants