DEV Community

Cover image for Mind blowing VS Code trick 🤫
Manitej ⚡
Manitej ⚡

Posted on • Edited on

4 2

Mind blowing VS Code trick 🤫

Hey guys! I recently found a nice shortcut that makes the javascript developers' life easier!

We use to import files in the below way,

import cart_styles from "../../styles/cart.css";
import product_styles from "../../styles/product.css";
import user_styles from "../../styles/product.css";
Enter fullscreen mode Exit fullscreen mode

This starts looking ugly and redundant if there are multiple imports from a parent folder that's above in the hierarchy.

Luckily, there's a neat shortcut in VS Code that solves this issue.

With the help of this trick, we can import files in the following way,

import cart_styles from "@styles/cart.css";
import product_styles from "@styles/product.css";
import user_styles from "@styles/product.css";
Enter fullscreen mode Exit fullscreen mode

I think this is a game-changer for me. So here's how to do this.

Step 1

Create a jsconfig.json file in the root directory

Step 2

Add the below code,

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@styles/*": ["styles/*"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Feel free to add new folders If you have any.

That's it. From now you can simply use @styles/ instead of ../../

What do you think about this trick? let me know in the comments :)

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay