Babel preset that removes Flow type annotations from JavaScript code during compilation.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Babel preset that removes Flow type annotations from JavaScript code during compilation. This preset provides a single plugin configuration that transforms Flow-typed JavaScript into standard JavaScript by stripping type annotations, making it ideal for development workflows where type safety aids development but clean JavaScript is needed for production.
npm install --save-dev babel-preset-flowThe preset is configured in Babel configuration files rather than imported directly:
.babelrc
{
"presets": ["flow"]
}babel.config.js
module.exports = {
presets: ["babel-preset-flow"]
};package.json
{
"babel": {
"presets": ["flow"]
}
}Transform Flow-typed JavaScript to standard JavaScript:
Input (Flow code)
// @flow
function add(x: number, y: number): number {
return x + y;
}
type User = {
name: string,
age: number,
active: boolean
};
const user: User = {
name: "Alice",
age: 30,
active: true
};Output (transformed)
function add(x, y) {
return x + y;
}
const user = {
name: "Alice",
age: 30,
active: true
};babel-preset-flow is a simple wrapper preset that encapsulates a single Babel plugin within the Babel ecosystem:
babel-plugin-transform-flow-strip-types pluginThe preset exports a configuration object that tells Babel which plugins to apply during compilation. This design pattern allows developers to enable Flow support with a single preset rather than manually configuring individual plugins.
The main export provides a Babel preset configuration that strips Flow type annotations.
import transformFlowStripTypes from "babel-plugin-transform-flow-strip-types";
/**
* Default export containing Babel preset configuration
* @returns Preset configuration object with Flow plugin
*/
export default {
plugins: [transformFlowStripTypes]
};The preset can be used in three primary ways:
Via .babelrc (Recommended)
{
"presets": ["flow"]
}Via CLI
babel --presets flow src --out-dir libVia Node API
require("babel-core").transform("code", {
presets: ["flow"]
});/**
* Internal dependency providing Flow type stripping functionality
*/
import transformFlowStripTypes from "babel-plugin-transform-flow-strip-types";This preset wraps the babel-plugin-transform-flow-strip-types plugin, which handles:
The preset integrates seamlessly with existing Babel configurations and can be combined with other presets:
{
"presets": [
"babel-preset-flow",
"@babel/preset-env"
]
}Works with all Babel-compatible build tools including webpack, Rollup, Parcel, and Create React App.