![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
babel-plugin-resolve-barrel-files
Advanced tools
A babel plugin that solves typescript barrel files
This plugin parses and resolves a barrel file
What is a barrel file?
Usually, index files with a lot of export statements, more info here
Given a module that export its dependencies using a barrel file like this:
// my-lib/index.js
export { map } from './dist/map';
export { chain } from './dist/chain';
export { filter } from './dist/filter';
export { groupBy } from './dist/groupBy';
And that you import it like this:
import { map, chain } from 'my-lib';
it will transform your code to:
import { map } from 'my-lib/dist/map';
import { chain } from 'my-lib/dist/chain';
Since a barrel file exports all files from a lib, babel/bundlers usually will import and parse all of those files because they can have side effects.
This plugin will drop unused imports from barrel files at lib roots, which will also remove import side effects.
This probably can help you to reduce the bundle size and help your bundler to be faster.
Because React Native sucks (or I suck because I don't know how to do this in metro).
Right now, this plugin doesn't support full imports like:
import all from 'my-lib'
We could ignore this, in the future and just warn that this kind of import make this plugin useless.
Since this plugin is meant to make the barrel file 'invisible' to the bundler, it will not resolve local exports.
a barrel file like this:
export default "foo";
if (!x) {
throw Error("foo")
}
Will do nothing
CommonJS is supported, although a lot of corner cases are not supported because I wrote myself the code to find and track exports. (PR welcome, would love to improve the CJS support)
Usually, a babel generated CommonJS will work fine.
npm install --save babel-plugin-resolve-barrel-files
# or
yarn add -D babel-plugin-resolve-barrel-files
Declare it in your babel config file:
const path = require('path');
module.exports = {
// ...,
plugins: [
[
'resolve-barrel-files',
{
'my-lib': {
moduleType: 'commonjs', // or 'esm'
barrelFilePath: require.resolve('my-lib')
// if you want to debug this plugin
// logLevel: "debug" | "info"
},
},
]
]
}
Note: if you make changes to the babel config be sure to restart your bundler with a clear babel cache
Feel free to open a PR or an issue and I'll try to help you :D
Heavily inspired by babel-plugin-transform-imports
FAQs
A babel plugin that solves typescript barrel files
The npm package babel-plugin-resolve-barrel-files receives a total of 2 weekly downloads. As such, babel-plugin-resolve-barrel-files popularity was classified as not popular.
We found that babel-plugin-resolve-barrel-files demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.