Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoscan #70

Open
oklas opened this issue Mar 15, 2022 · 7 comments
Open

autoscan #70

oklas opened this issue Mar 15, 2022 · 7 comments

Comments

@oklas
Copy link
Owner

oklas commented Mar 15, 2022

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',
    },
  ]
}
@oklas
Copy link
Owner Author

oklas commented Mar 27, 2022

As of now this feature is not working for typescript. It requires to specify alias in tsconfig.paths.json anyway.

@oakfang
Copy link

oakfang commented Aug 8, 2022

Great feature, please keep it in!

@SPiCaRiA
Copy link

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';

@oklas
Copy link
Owner Author

oklas commented Oct 26, 2022

Hi @SPiCaRiA, what is the problem, what is actually not worked for you? Error or something else.

@SPiCaRiA
Copy link

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'?

@oklas
Copy link
Owner Author

oklas commented Oct 28, 2022

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)

@SPiCaRiA
Copy link

#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants