Skip to content

Instantly share code, notes, and snippets.

@baliyan9887
Last active January 26, 2024 09:37
Show Gist options
  • Save baliyan9887/205ce3c12561f3ce46c90d955b94a1a7 to your computer and use it in GitHub Desktop.
Save baliyan9887/205ce3c12561f3ce46c90d955b94a1a7 to your computer and use it in GitHub Desktop.
This configuration file is designed to enhance the development experience in a JavaScript project. It leverages JavaScript Compiler Options for better code organization, readability, and maintainability.
{
// JavaScript compiler options
"compilerOptions": {
// Set the base URL for all relative module imports.
// This helps in having cleaner and shorter import paths.
"baseUrl": ".",
// Define path aliases for commonly used directories.
// This improves the readability of import statements.
"paths": {
"@src/*": ["src/*"],
"@components/*": ["src/components/*"],
"@utils/*": ["src/utils/*"],
"@services/*": ["src/services/*"],
"@styles/*": ["src/styles/*"],
"@assets/*": ["src/assets/*"]
},
// Enable ES module interoperability.
// This allows compatibility between CommonJS and ES module systems.
"esModuleInterop": true,
// Specify JSX as the target language.
// This is essential for working with React components.
"jsx": "react",
// Specify the module system for the emitted code.
// ESNext is a good choice for modern JavaScript applications.
"module": "esnext",
// Set the ECMAScript version to target.
// ESNext allows you to use the latest ECMAScript features.
"target": "esnext",
// Allow synthetic default imports from modules with no default export.
// This simplifies the import syntax for modules without default exports.
"allowSyntheticDefaultImports": true,
// Skip type checking of declaration files.
// Useful for improving build performance.
"skipLibCheck": true,
// Force consistent casing in file names.
// This helps avoid potential issues on case-sensitive file systems.
"forceConsistentCasingInFileNames": true
},
// Exclude specified files and directories from JavaScript compilation.
// This ensures that certain directories are not processed by the TypeScript compiler.
"exclude": ["node_modules", "build", "dist", "coverage"]
}
@baliyan9887
Copy link
Author

Usage

Now that you have set up the jsconfig.json file, you can leverage path aliases in your project for cleaner and more maintainable imports. Here's an example:

Before:

import MyComponent from '../../../components/MyComponent';

After:

import MyComponent from '@components/MyComponent';

By using path aliases, you simplify your import statements, making your codebase more readable and easier to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment