Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace imports but keep string

I would like to know if there is any way to make the following change to all files at once

import component from 'Components/Path/compoent.ts'

to

const component = () => import('Components/Path/compoent.ts')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In case you want to replace everything with this syntax, then a regex is your friend here:

import (\S+) from '([^']+)'

Replace with:

const $1 = () => import('$2')

To just replace the constant string:

import component from '([^']+)'

Replace with:

const component = () => import('$1')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading