Last active
March 9, 2025 22:49
-
-
Save wojtekmaj/41b0724cbb81b8ab740d5ee403dbc2ec to your computer and use it in GitHub Desktop.
Visual Studio Code-compatible regular expression to add all missing import extensions
This file contains hidden or 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
# Find | |
import\s(([^;]|\n)*)\sfrom\s(['"])(\.{1,2}\/.*)(?<!\.js)(?<!\.(css|pdf|png|jpg|jsx|mjs|mp3|mp4|svg|ttf))(?<!\.(avif|json|webm|webp|woff))(?<!\.woff2)(['"]); | |
# Replace with | |
import $1 from $3$4.js$7; |
Thanks, this saved a lot of time
Here's a version that works with @
imports too:
import\s(([^;]|\n)*)\sfrom\s(['"])(\.{1,2}\/.*|@[^\/]*\/?.*)(?<!\.js)(?<!\.(css|pdf|png|jpg|jsx|mjs|mp3|mp4|svg|ttf))(?<!\.(avif|json|webm|webp|woff))(?<!\.woff2)(['"]);
Replace expression is same:
import $1 from $3$4.js$7;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent thanks, it also works well for
export
👍