love
V2EX  ›  React

create-react-app + typescript,前后端共享一些 ts 文件怎么办?

  •  
  •   love · May 26, 2020 · 1887 views
    This topic created in 2185 days ago, the information mentioned may be changed or developed.

    目录

    + my-app
      + server
        - package.json
        + shared
          - types.ts
      + web
        - package.json
        + src
          - index.ts // 这里要引用 server/shared/types.ts
    

    web 目录是用 create-react-app 建立的,但是 cra 限制 web/src 里的文件不能直接引用 src 外的文件,这要怎么办? 你们是怎么用 cra 的同时前后端共享文件的?

    Supplement 1  ·  May 26, 2020
    解决了,原来不能直接引用 src 外面文件但可以在 src 建个 symbolic link 到 server 的 dist 目录
    hantsy
        1
    hantsy  
       May 28, 2020
    不知道 cra 怎么回事,Angular CLI 现在是 Workspace 概念,可以同时 Run 多个 Project 。另外有很多遵循 MonoRepos 设计模式,如 nx.dev ,也是扩展了 Angular 概念 ,也支持 React 了,可以不同项目共享代码。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1480 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    ♥ Do have faith in what you're doing.