Webpack/V5/Json Imports To Default Imports
Made for
Webpack
Last update
Sep 8, 2024
This codemod migrates imports from JSON modules that use named exports to use default exports instead.
It replaces code like import { version } from './package.json'; console.log(version);
with import pkg from './package.json'; console.log(pkg.version);
.
Example
Before
import { version } from './package.json';console.log(version);
After
import pkg from './package.json';console.log(pkg.version);
,
Before
import { version, name, description } from './package.json';console.log(version, name, description);
After
import pkg from './package.json';console.log(pkg.version, pkg.name, pkg.description);
,
Before
import { nested, nested2 } from './data.json';console.log(nested.property, nested2.property);
After
import pkg from './data.json';console.log(pkg.nested.property, pkg.nested2.property);
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community