Reputation: 283043
If I use the babel-plugin-transform-runtime
plugin, then my code will import
/require
babel-runtime
instead of including all those helper functions inline. This is nice, but it makes my library have a dependency babel-runtime
. What I would rather do is have Babel extract one extra file (./babel-runtime
) and drop that in with the other output files so that I don't have to include it as an external dependency. i.e., I won't have to add that to package.json
everywhere my library is used. Is this possible?
Upvotes: 2
Views: 1203
Reputation: 283043
The only solution I found was to not use the babel-plugin-transform-runtime
plugin and add exclude: ['transform-regenerator']
to your config. This will prevent Babel from adding a dependency on regenerator. It also means your code won't run in older browsers.
If you need support for older browsers, you can try fast-async
. It says there's a way to inline the dependency in just your index file, but I haven't tried it yet. I believe this assumes the browser supports Promises but not async/await.
Upvotes: 1
Reputation: 92579
You can import custom module instead of babel-runtime
by using the moduleName
option in the transform-runtime
plugin:
{
"plugins": [
["transform-runtime", {
"moduleName": "./babel-runtime"
}]
]
}
Upvotes: 1