Smart Import is another method of adding import
or require
statements to your code. By right-clicking a file and selecting "Smart Import" from the context menu, the extension calculates the relative path and automatically inserts the correct syntax for your module imports at the top of your currently open file.
- Context Menu Integration: Quickly add import or require statements by right-clicking a file and selecting "Smart Import".
- Dynamic Import Method: Automatically uses
import
orrequire
based on the file type and editor language. - Relative Path Calculation: Ensures correct module location using
path.relative
. - Cross-Platform Compatibility: Converts backslashes (
\
) to forward slashes (/
) for all OS compatibility. - User Feedback: Confirms import addition with a message in the information bar.
- Open a file in VS Code.
- In the Explorer pane, right-click on the file containing the exports that you want to import.
- Select "Smart Import" from the context menu.
- The appropriate
import
orrequire
statement will be automatically inserted at the top of the currently active file.
If you right-click on myModule.js
in the Explorer and select "Smart Import" while index.js
is the active editor, the following statement will be added to the top of index.js
:
import something from "./path/to/myModule";
- Ensure you have Node.js and npm installed on your system.
- Clone the repository and navigate to the project directory.
- Run
npm install
to install the necessary dependencies. - Compile the extension by running
npm run compile
. - Package the extension with
vsce package
. - Install the packaged extension in VS Code using
code --install-extension smart-import-0.0.1.vsix
. - Reload your VS Code window to begin using the extension.