ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 49 forks source link

update readme for latest metro bundler #87

Closed koenpunt closed 5 years ago

koenpunt commented 6 years ago

When using the latest version of react native (0.57.4), the previous config did no longer work. It might be practical to leave both in the readme, because older RN versions of course still require the old config.

I'm not sure when RN switched to the newer version of Metro, but I could look this up, and update the README with configuration examples before and after a certain RN version.

tonyxiao commented 6 years ago

I'm not sure if we should actually be updating resolver.sourceExts here. By default metro already comes with sourceExts: [ 'js', 'json', 'ts', 'tsx' ], due to babel7's typescript support. This may also change in the future also and sourceExts array is not merged.

This is sufficient

module.exports = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-typescript-transformer')
  }
}
fantasy525 commented 6 years ago

When using the latest version of react native (0.57.4), the previous config did no longer work. It might be practical to leave both in the readme, because older RN versions of course still require the old config.

I'm not sure when RN switched to the newer version of Metro, but I could look this up, and update the README with configuration examples before and after a certain RN version.

0.57.5,I find the following configuration still valid

module.exports = {
    getTransformModulePath() {
        return require.resolve('react-native-typescript-transformer');
    },
    getSourceExts() {
        return ['ts', 'tsx'];
    }
}
koenpunt commented 6 years ago

0.57.5,I find the following configuration still valid

Which version of metro are you using? Did you specify the version for it explicitly in package.json?

fantasy525 commented 6 years ago

0.57.5,I find the following configuration still valid

Which version of metro are you using? Did you specify the version for it explicitly in package.json?

what do you mean metro version? Is metro-react-native-babel-preset? here my package.json:

"dependencies": {
    "react": "16.6.1",
    "react-native": "0.57.5",
    "tslib": "^1.9.3"
  },
  "devDependencies": {
    "@types/react": "^16.7.6",
    "@types/react-native": "^0.57.10",
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.49.2",
    "react-native-typescript-transformer": "^1.2.10",
    "react-test-renderer": "16.6.1",
    "typescript": "^3.1.6"
  },
koenpunt commented 6 years ago

Not sure how that still works, but since 0.57.0 the default config is also using the new format (https://github.com/facebook/react-native/commit/a32620dc3b7a0ebd53feeaf7794051705d80f49e), but maybe there's some sort of compatibility mode, which maps the old config to new config. Although that didn't seem to work for me..

fantasy525 commented 6 years ago

Not sure how that still works, but since 0.57.0 the default config is also using the new format (facebook/react-native@a32620d), but maybe there's some sort of compatibility mode, which maps the old config to new config. Although that didn't seem to work for me..

module.exports = {
transformer: {
babelTransformerPath: require.resolve('react-native-typescript-transformer')
}
}

this didn't work for me,0.57.5,I test ...

ds300 commented 5 years ago

Thanks!