Skip to content

Commit

Permalink
breaking: Option react must now be false, true, “lib”, “dom” or…
Browse files Browse the repository at this point in the history
… “dom-lib”

Signed-off-by: Jaid <jaid.jsx@gmail.com>
  • Loading branch information
Jaid committed May 31, 2021
1 parent 5911645 commit 19fc22e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const debug = require("debug")(process.env.REPLACE_PKG_NAME)

/**
* @typedef {Object} options
* @prop {boolean|string} [react=false] If `true` or typeof `string`, `react`-related plugins and presets are included. If `react-, `react-dom`-related plugins and presets are also included.
* @prop {boolean|"dom"|"dom-lib"|"lib"} [react=false] If `true` or typeof `string`, `react`-related plugins and presets are included. If it's “dom” or “dom-lib”, `react-dom`-related plugins and presets are also included. If it's “lib” or “dom-lib”, it will be handled as library to use in other packages.
* @prop {boolean} [runtime=true] If `true`, `@babel/plugin-transform-runtime` will be applied.
* @prop {boolean|Object} [minify=true] If `false`, `babel-minify` won't be applied to production builds. If `true`, `babel-fy` will be applied with `{removeConsole: false, removeDebugger: true}` as configuration. If typeof `object`, this will bed as `babel-minify` config.
* @prop {Object} [envOptions=null] If typeof `object`, this will be used as options for `@babel/preset-env`.
Expand All @@ -37,7 +37,6 @@ export default (api, options) => {
envOptions: null,
typescript: false,
aotLoader: true,
legacyDecorators: true,
outputConfig: false,
esm: false,
loose: false,
Expand Down Expand Up @@ -102,22 +101,28 @@ export default (api, options) => {
}

if (options.react) {
configBuilder.preset("@babel/preset-react", {
development: !api.env("production"),
})
configBuilder.pluginForEnv("production", "transform-react-class-to-function")
configBuilder.pluginForEnv("production", "transform-react-remove-prop-types")
configBuilder.pluginForEnv("production", "@babel/plugin-transform-react-inline-elements")
const reactType = typeof options.react === "string" ? options.react : "dom"
const isDom = reactType.startsWith("dom")
const isLib = reactType.endsWith("lib")
if (options.react) {
configBuilder.preset("@babel/preset-react", {
development: !api.env("production"),
})
if (!isLib) {
configBuilder.pluginForEnv("production", "transform-react-class-to-function")
configBuilder.pluginForEnv("production", "transform-react-remove-prop-types")
configBuilder.pluginForEnv("production", "@babel/plugin-transform-react-inline-elements")
}
}
if (isDom) {
configBuilder.pluginForEnv("development", "react-hot-loader/babel")
}
}

if (options.runtime) {
configBuilder.plugin("@babel/plugin-transform-runtime")
}

if (options.react === "react-dom") {
configBuilder.pluginForEnv("development", "react-hot-loader/babel")
}

if (options.minify) {
const defaultMinifyOptions = {
removeConsole: false,
Expand Down

0 comments on commit 19fc22e

Please sign in to comment.