@alot/transformer
A TypeScript and Babel transformer for React Native.
Last updated 2 years ago by frielforreal .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @alot/transformer 
SYNC missed versions from official npm registry.

@alot/transformer

Use TypeScript and ES6+ directly in your React Native projects.

This is a fork of ds300/react-native-typescript-transformer and facebook/metro-bundler with an extra environment variable, PLATFORM_TARGET. See Platform Specific Builds for more information.

Usage

  1. Add as a dependency:

    yarn add --dev @alot/transformer

  2. Create a tsconfig.json configuration in your app root if you haven't already, for example:

    {
      "compilerOptions": {
        "target": "es2015",
        "jsx": "react",
        "noEmit": true,
        "moduleResolution": "node"
      },
      "exclude": [
        "node_modules"
      ]
    }
    
  3. Modify or create a rn-cli.config.js in your app to define getTransformModulePath and getSourceExts, as follows:

    module.exports = {
      getTransformModulePath() {
        return require.resolve('@alot/transformer')
      },
      getSourceExts() {
        return ['ts', 'tsx'];
      }
    }
    
  4. That's it, add .ts and .tsx files to your project and React Native will load them!

Platform specific builds

You might wish to specify different tsconfig.json or .babelrc configurations for different platform targets, one for android, one for web, and so on. Set an environment variable PLATFORM_TARGET before running your build to search for these configuration files in that folder. If .babelrc and tsconfig.json aren't found there, the app root will be searched afterward.

An example package.json script might look like:

  {
    "scripts": {
      "expo": "cross-env PLATFORM_TARGET=expo react-native-scripts start --reset-cache"
    }
  }

This will cause the transformer to search the expo folder for .babelrc and tsconfig.json. This might be necessary because expo uses a custom babel configuration, which might be incompatible with other platforms.

Smaller bundles with tslib

Instead of defining helper functions in each transpiled module, TypeScript can use a shared library like Babel's use of a polyfill library.

  1. Add tslib:

    yarn add tslib

  2. Add "importHelpers": "true" to the compilerOptions of your tsconfig.json:

     {
      "compilerOptions": {
        ...
    +    "importHelpers": true,
        ...
      }
     }
    

Current Tags

  • 1.3.4                                ...           latest (2 years ago)

14 Versions

  • 1.3.4                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.5                                ...           2 years ago
  • 1.2.4                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.2-2                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 14
Last Day 0
Last Week 14
Last Month 34
Dependencies (8)
Dev Dependencies (6)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |