VSCode extension that attempts to deduce aliased module paths.
- Install plugin
- CMD/CTRL + Click, F12, or right click -> Go To Definition on import paths
- (optional performance boost): In vscode settings, Editor > Goto Location: Multiple Definitions > goto. This will open the winning result first. It the settings.json, it's
"editor.gotoLocation.multipleDefinitions": "goto".
-
smart-goto.resolveExtensions: string[]- String array of the extensions you don't have to add the extension to. I recommend to not do things like.css,.scss. You really only want to resolve.js,.jsx, etc. -
smart-goto.ignoreFolders: string[]- String array of folders to to parse when creating internal dependency search stream. Default isnode_modulesand.git.
Sometimes aliases are defined in webpack, Typescript settings, or babel to avoid relative imports. I got tired of having to copy/paste the paths and type it into vscode's fuzzy search for certain projects I was working on.
If you’re not familiar with the concept of aliasing, it turns a file like this:
import React from 'react'
import { connect } from 'react-redux'
import { someConstant } from './../../config/constants'
import MyComponent from './../../../components/MyComponent'Into this:
import React from 'react'
import { connect } from 'react-redux'
import { someConstant } from 'config/constants'
import MyComponent from 'components/MyComponent'- Automatic aliases deduction
apps/components/core -> /Users/example/source/app-name/src/apps/components/core/index.js - Finds and locates
indexfiles - Finds and opens files when extension provided
- Faster than tsserver in most cases
- Coming Soon:
- Automatic
baseDirinference based ontsconfig.json - Automatic
baseDirinference based onpackage.jsonhaving amoduleRootsproperty
- Automatic
- Right now, I don't support weird aliases like
@components. I plan on adding support for that soon. - Use of
jsconfig.jsonandtsconfig.json. If you have paths/basePaths configured there, it'll work for all JS/TS - Support for more extensions
- Custom config for aliasing in
.vscode/settings.jsonconfig:
{
"smart-goto.paths": {
"@components": "src/components"
}
}This will speed up resolution/linking by a massive amount.