coolair
V2EX  ›  问与答

项目如何引用某个仓库的 src 到当前仓库的某个文件夹作为组件?

  •  
  •   coolair · Jan 27, 2022 · 1215 views
    This topic created in 1574 days ago, the information mentioned may be changed or developed.

    自己有个私有的前端库:

    MyComponent
       |---src
    

    目前做法是直接拷贝 src 至项目中并重命名为 MyComponent 使用:

    MyProject
       |---Components
       |         |---MyComponent
    

    这样做的话,如果 MyComponent 的代码更新了,就得重新拷贝复制一份,如果项目中的 MyComponent 有个性话的修改那就得对比代码看了,很麻烦。

    目前想,这个目录引用原仓库,但是只有这个目录。

    git submodule我看好像是整个仓库引用,而不能单独引用某个文件夹?

    有什么好的解决办法吗?

    3 replies    2022-01-27 15:17:46 +08:00
    illuz
        1
    illuz  
       Jan 27, 2022 via Android
    软链?
    kaifeiji
        2
    kaifeiji  
       Jan 27, 2022
    可以试试软链接:

    1 、项目库的 Components 建一个软链接 -> 组件库的 src 目录
    2 、项目库的 gitignore 添加软链接路径
    TomVista
        3
    TomVista  
       Jan 27, 2022
    cd MyProject/Components
    git clone MyComponent

    git pull --rebase // 更新 MyComponent

    import @Components/MyComponent/src/index.js

    至于你说的只想拉下来 src, 请相信前端的 tree shaking 能力
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1190 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 23:26 · PVG 07:26 · LAX 16:26 · JFK 19:26
    ♥ Do have faith in what you're doing.