Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@mikojs/babel-plugin-transform-flow

mikojs19MIT1.17.0

Use to build the flow files with babel.

babel plugin, mikojs, transform flow files

readme

@mikojs/babel-plugin-transform-flow · npm npm-size

Use to build the flow files with babel.

Example

In

├── index.js
├── index.js.flow
└── lib.js

Out

├── index.js
├── index.js.flow // if flow file exist in the source folder, just copy file to the target folder.
├── lib.js
└── lib.js.flow // if flow file does not exist in the source folder, transform the file with plugins to the target folder.

Install

yarn add @mikojs/babel-plugin-transform-flow --dev

Add @mikojs/babel-plugin-transform-flow to babel config.

...
  plugins: [
    ...
    '@mikojs/transform-flow',
    ...
  ]
...

With the custom options

...
  plugins: [
    ...
    [
      '@mikojs/transform-flow',
      {
        dir: './cutom-output-dir-path',
        relativeRoot: './relativeRoot-path-from-root',
        presets: ['other-babel-presets'],
        plugins: ['other-babel-plugins'],
        verbose: false,
        ignore: /ignore-pattern/,
      },
    ],
    ...
  ]
...

This plugin use babel.transformsync to build the flow files. This will read the parserOpts from your babel config automatically. However, we need to transform the code somtime.

For example, pipeline is not supported by flow. As a result, we need to add @babel/proposal-pipeline-operator in the plugins option to make @mikojs/babel-plugin-transform-flow transform the pipeline before build the file.