Skip to content

Commit

Permalink
feat: react and flow options
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 9, 2020
1 parent c36d8a9 commit a5c8240
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ let presets = [
];
```

6) `react`

Enable `"@babel/preset-react"`. `true` by default

7) `flow`

Enable `"@babel/preset-flow"`. `true` by default


## Behind the scenes

It includes the following presets:
Expand Down
27 changes: 22 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (process.env.BABEL_KEEP_MODULES === "true") {
}

function handleOptions(options) {
let {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap } = options
let {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow } = options

// use Electron 5 targets by default
if (targets == null) {
Expand Down Expand Up @@ -34,12 +34,20 @@ function handleOptions(options) {
sourceMap = "inline"
}

return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap }
if (react == null) {
react = true
}

if (flow == null) {
flow = true
}

return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow }
}

module.exports = (api, options, dirname) => {

const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap } = handleOptions(options)
const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow } = handleOptions(options)

let presets = [
[
Expand All @@ -49,10 +57,19 @@ module.exports = (api, options, dirname) => {
modules: keepModules ? false : "commonjs"
},
],
require("@babel/preset-react"),
require("@babel/preset-flow"),
];

if (react) {
presets.push(...[
require("@babel/preset-react"),
]);
}

if (flow) {
presets.push(...[
require("@babel/preset-flow"),
]);
}

let plugins = [
require("@babel/plugin-proposal-function-bind"),
Expand Down

0 comments on commit a5c8240

Please sign in to comment.