Last active
September 10, 2022 20:47
-
-
Save darkmavis1980/38fde6f86c72cfd29242365aeb29e209 to your computer and use it in GitHub Desktop.
Replace require with ESM import in VS Code find/replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* search for: | |
* const x = require('x'); | |
* const { a } = require('a'); | |
*/ | |
const ([\w\s\n,{}:]+) = require\('([.\/@\w-]+)'\) | |
/** | |
* replace with: | |
* import x from 'x'; | |
* import { a } from 'a'; | |
*/ | |
import $1 from '$2' | |
/** | |
* But it will not do the aliases, like: | |
* const { a: b } = require('a'); | |
* to do so, use this: | |
*/ | |
([\w]+): ([\w]+) | |
// Replace with | |
$1 as $2 | |
/** | |
* Search for JSON attributes to conver to JS | |
*/ | |
"([a-z]+)": | |
//replace it with | |
$1: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment