I'm using Babel to package my module but I'm running into a problem with React dependency. Since some version of React, it's no longer required to explicitly import it to use JSX, and my formatter config takes full advantage of that by stripping unnecessary import statements. This works just fine in my webpack build.
However, when I use Babel to produce dist
folder for the package, I end up with code like this
var colored = function colored(text, color) {
return text != null && /*#__PURE__*/React.createElement("span", {
className: "color-".concat(color)
}, text);
};
This obviously uses React
, but it's not imported anywhere! And as expected, it crashes on runtime.
My babel config:
{
"presets": [
[
"react-app",
{
"absoluteRuntime": false
}
]
],
"plugins": [
[
"module-resolver",
{
"root": ["./src"],
"alias": {
"@": "./src"
}
}
],
[
"babel-plugin-transform-remove-imports",
{
"test": "\\.(css|scss)$"
}
],
[
"@babel/plugin-transform-typescript",
{
"allowDeclareFields": true
}
]
]
}
NODE_ENV=production babel src --out-dir dist --copy-files --extensions \".ts,.tsx\" --config-file ./babel-build.config.json