V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
coolair
V2EX  ›  问与答

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

  •  
  •   coolair · 2022-01-27 13:31:08 +08:00 · 750 次点击
    这是一个创建于 841 天前的主题,其中的信息可能已经有所发展或是发生改变。

    自己有个私有的前端库:

    MyComponent
       |---src
    

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

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

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

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

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

    有什么好的解决办法吗?

    3 条回复    2022-01-27 15:17:46 +08:00
    illuz
        1
    illuz  
       2022-01-27 14:05:45 +08:00 via Android
    软链?
    kaifeiji
        2
    kaifeiji  
       2022-01-27 14:13:15 +08:00
    可以试试软链接:

    1 、项目库的 Components 建一个软链接 -> 组件库的 src 目录
    2 、项目库的 gitignore 添加软链接路径
    TomVista
        3
    TomVista  
       2022-01-27 15:17:46 +08:00
    cd MyProject/Components
    git clone MyComponent

    git pull --rebase // 更新 MyComponent

    import @Components/MyComponent/src/index.js

    至于你说的只想拉下来 src, 请相信前端的 tree shaking 能力
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2251 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:10 · PVG 09:10 · LAX 18:10 · JFK 21:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.