Closed enjoythecode closed 2 years ago
Webpack can be configured to have aliases with a syntax that looks like this:
module.exports = {
...
resolve: {
...
alias: {
...
'components': path.resolve(__dirname, '../src/components/'),
'images': path.resolve(__dirname, '../src/images/'),
},
...
},
...
};
Pros:
Exporting NODE_PATH=src
will make webpack look for folders inside the src
folder when importing without a relative path.
Pros:
This kind of configuration is supported in Create React App See Documentation
# contents of jsconfig.json
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Pros:
Chosen solution: Create React App Absolute Imports
Current Behavior
Currently, imports use relative imports that look like this:
This is inconvenient because the
../
prefix is file specific and requires hand-modification.Desired Behavior
Imports in any given file should not depend on the folder depth of a file.