Skip to content

Instantly share code, notes, and snippets.

@attebury
Last active August 23, 2020 09:31
Show Gist options
  • Save attebury/b15ebe5a949ea3df95ad8fba3b0263ba to your computer and use it in GitHub Desktop.
Save attebury/b15ebe5a949ea3df95ad8fba3b0263ba to your computer and use it in GitHub Desktop.
Regular Expression to add JS extension to module imports in Visual Studio Code
// Used in VS Code's Find and Replace
// Note that this will add JS extension to any import that already has .js
// You may want to search for .js.js after running this
// Find in folder(s)
(^import[\s{\w,?}]*[from]?\s)(['\.\/a-z\/\-]*)';?
// Replace
$1$2.js';

Example

Original

import { someModule } from '../some/module';

import {
  modOne,
  modTwo,
  modThree
} from '../utility/module';

import anotherModule from '../another-module';

Modified

import { someModule } from '../some/module.js';

import {
  modOne,
  modTwo,
  modThree
} from '../utility/module.js';

import anotherModule from '../another-module.js';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment