1.17.0 • Published 3 years ago

@mikojs/babel-plugin-transform-flow v1.17.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@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.