Skip to content

Instantly share code, notes, and snippets.

@darkmavis1980
Last active September 10, 2022 20:47
Show Gist options
  • Save darkmavis1980/38fde6f86c72cfd29242365aeb29e209 to your computer and use it in GitHub Desktop.
Save darkmavis1980/38fde6f86c72cfd29242365aeb29e209 to your computer and use it in GitHub Desktop.
Replace require with ESM import in VS Code find/replace
/**
* 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