react-app-alias
react-app-alias copied to clipboard
autoscan
Warn: Experimental feature. It is not documented and may be subject to remove.
Please ask a questions, share opinions and suggestions. Share your experience if you tried to use autoscan
.
const options = {
autoscan: 'src',
}
const options = {
autoscan: {
path: 'src',
prefix: '@', // optional
suffix: '_', // optional
}
}
const options = {
autoscan: [
'lib',
{
path: 'src',
},
]
}
As of now this feature is not working for typescript
. It requires to specify alias in tsconfig.paths.json
anyway.
Great feature, please keep it in!
Hi, thank you for the awesome feature! Not sure if this is the right place to ask related questions but:
The example usage demonstrates how it can make alias (Internal/index
) for the folders under src
. Apart from this, is it possible for autoscan to make alias for files under src
? For example, imagine having the file structure:
- src
- App.js
- Foo.js
And I want to use absolute imports as if I set baseUrl
as src
so I can write code like this in App.js
:
// In App.js.
import Foo from 'Foo';
Hi @SPiCaRiA, what is the problem, what is actually not worked for you? Error or something else.
Hi @SPiCaRiA, what is the problem, what is actually not worked for you? Error or something else.
Hi, sorry I didn't make it clear:
In my config-override.js:
const options = {
autoscan: 'src',
}
module.exports = aliasWebpack(options)
jsconfig.json and jsconfig.path.json:
{
"extends": "./jsconfig.paths.json",
"compilerOptions": {
"baseUrl": "."
},
"include": ["src"]
}
{
"compilerOptions": {
"paths": {
"*": ["src/*"]
}
}
}
The usage:
import foo from 'my_dir/foo' // works
import bar from 'bar' // does not work, needs to be ./bar
Yes it throws an error: Can't resolve 'bar' in '/dir/to/root/src' Did you mean './bar'?
Yes it requires a little fix, track it #89.
As of now you can try to use file import, like this:
- import bar from 'bar'
+ import bar from 'bar/index'
May be it need to specify extension (.js or .ts)
#89
Hmm, not sure if I'm understanding it correctly, but in my case bar
is just a JavaScript module, not the index.js
🤔
Am I wrong about what autoscan does at the very beginning? I thought it does something similar as the CRA absolute imports. :x