SWC Plugin for Import Transformation

Link: https://github.com/ankitchouhan1020/swc-plugin-transform-import

Some libraries look tree-shakeable in source and still land as a fat require('lodash') in the bundle. Member imports like import { merge } from 'lodash' become “load the package, then pick a property” — fine for Node, expensive when webpack can’t prove the rest is dead.

babel-plugin-transform-imports fixed that in the Babel world by rewriting those imports to deep paths. swc-plugin-transform-import is the same idea for SWC — useful when you’re already on swc-loader and don’t want a Babel pass just for this.

What it does

import { Row, Grid as MyGrid } from 'react-bootstrap';
import { merge } from 'lodash';

becomes something like:

import Row from 'react-bootstrap/lib/Row';
import MyGrid from 'react-bootstrap/lib/Grid';
import merge from 'lodash/merge';

Configure per package (transform template, preventFullImport, etc.), wire it through swc-loader’s plugin hook, and keep writing ergonomic named imports in app code.

Why I wrote it

I hit this while chasing bundle size on real product code — the same class of problem as the re-export / tree-shaking notes under Writing. Babel had a plugin; SWC didn’t, in the shape I needed. So this exists: a small compile-time transform so the bundler sees the imports you meant.

Install: npm i -D swc-plugin-transform-import
Source: github.com/ankitchouhan1020/swc-plugin-transform-import