This codemod transforms import {$A} from '$env/dynamic/public'; and import {$A} from '$env/dynamic/private'; into their static counterparts, replacing them with import {$A} from '$env/static/public'; and import {$A} from '$env/static/private';, respectively. It ensures compatibility for prerendered pages and static deployments.
Note: This is a contrived example. Please modify it according to your use case.
Example
Before
// $env/dynamic/privateimport { PRIVATE_API_KEY } from '$env/dynamic/private';/** @type {import('./$types').PageServerLoad} */export function load() {const apiKey = PRIVATE_API_KEY;return { apiKey };}// $env/dynamic/publicimport { PUBLIC_API_URL } from '$env/dynamic/public';/** @type {import('./$types').PageLoad} */export function load() {const apiUrl = PUBLIC_API_URL;return { apiUrl };}
After
// $env/static/privateimport { PRIVATE_API_KEY } from '$env/static/private';/** @type {import('./$types').PageServerLoad} */export function load() {const apiKey = PRIVATE_API_KEY;return { apiKey };}// $env/static/publicimport { PUBLIC_API_URL } from '$env/static/public';/** @type {import('./$types').PageLoad} */export function load() {const apiUrl = PUBLIC_API_URL;return { apiUrl };}
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community