Giter Site home page Giter Site logo

work-record's Introduction

Hi there 👋

work-record's People

Contributors

sheepeer avatar

Watchers

 avatar

work-record's Issues

add alias for create-react-app with typescript

version:
"react": "^17.0.2",
"typescript": "^4.5.4",
"webpack": "^5.64.4",

引入typescript 后,webpack.conf.js 中已经生成了对 alias 的配置:
image

查看 webpackAliases:
image
ps:console.log 是我自己加的

getWebpackAliases 函数:
image

返回值也就是生成的 webpack alias 配置:
image
默认生成的是 src: ,我希望使用 @ 代替 src,所以自己改了一下

总结:只需要在 tsconfig.json 中配置 baseUrl、paths 和 include 字段:

{
  "compilerOptions": {
    ...
    "baseUrl": ".",
      "paths": {
          "@/*": [
              "./src/*"
          ]
      }
  },
  "include": [
    "src"
  ],
  ...
}

但不知道为什么,将 baseUrl 和 paths 写在 tsconfig.paths.json,然后在 tsconfig.json 中 extends tsconfig.paths.json ,会导致 webpack 读不到 baseUrl 和 paths 的值(?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.