craco-alias https://github.com/risenforces/craco-alias#examples
    image.png

    1. yarn add craco-alias -D
    1. 项目根目录创建 tsconfig.extend.json
    2. 配置文件如下

      1. {
      2. "compilerOptions": {
      3. "baseUrl": "./src",
      4. "paths": {
      5. // file aliases 使用index.tsx的写法
      6. "@baz": ["./baz.ts"],
      7. "@boo": ["./boo.tsx"],
      8. // folder aliases 使用别名下的模块的写法
      9. "@root": ["./"],
      10. "@root/*": ["./*"],
      11. "@lib": ["./lib"],
      12. "@lib/*": ["./lib/*"],
      13. // package aliases
      14. "@my-react-select": [
      15. "../node_modules/react-select",
      16. "../node_modules/@types/react-select"
      17. ],
      18. "@my-react-select/*": [
      19. "../node_modules/react-select/*",
      20. "../node_modules/@types/react-select"
      21. ]
      22. }
      23. }
      24. }
    3. tsconfig.json,extends ```json {

    • “extends”: “./tsconfig.extend.json”, “compilerOptions”: { … }, } ```
    1. craco.config.js ```json const CracoAlias = require(“craco-alias”);

    module.exports = { plugins: [ { plugin: CracoAlias, options: { source: “tsconfig”, // baseUrl SHOULD be specified // plugin does not take it from tsconfig baseUrl: “./src”, // tsConfigPath should point to the file where “baseUrl” and “paths” are specified tsConfigPath: “./tsconfig.extend.json” } } ] } ```