GM
V2EX  ›  Node.js

为什么前端界这么喜欢用 @ 号做为包名前缀?有什么好处或者目的吗?

  •  
  •   GM · Sep 23, 2021 · 10154 views
    This topic created in 1695 days ago, the information mentioned may be changed or developed.
    17 replies    2021-10-25 10:16:05 +08:00
    AoEiuV020
        1
    AoEiuV020  
       Sep 23, 2021   ❤️ 1
    带 @多一级不会和别人重复,比如我有个包叫 hello, 但全局的 hello 已经有人占了,我就可以发在自己名下叫做 @AoEiuV020/hello
    randyo
        2
    randyo  
       Sep 23, 2021
    最近配置 .npmrc,设置了 registry 为淘宝源,又设置另一个私有包到私有源,发现不带 @ 它就走淘宝源,给私有包加了 @ 再配置,就可以了。这个私有包走私有源,其他包走淘宝源。
    L1shen
        4
    L1shen  
       Sep 23, 2021   ❤️ 2
    @ 代表是 npm 上的一个组织,也有命名空间的作用
    ayase252
        5
    ayase252  
       Sep 23, 2021
    避免 npm 包命名冲突。
    比如 facebook 上传了个叫 react 的包,其他所有开发者都不能够使用 react 这个名字了。
    cydysm
        6
    cydysm  
       Sep 23, 2021
    https://docs.npmjs.com/cli/v7/using-npm/scope
    这个叫 scope
    Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package.

    Each npm user/organization has their own scope, and only you can add packages in your scope. This means you don't have to worry about someone taking your package name ahead of you. Thus it is also a good way to signal official packages for organizations.
    suzic
        7
    suzic  
       Sep 23, 2021 via Android
    好像是谷歌先这么干的
    dropsio
        8
    dropsio  
       Sep 23, 2021
    一切源于模仿...
    Biwood
        9
    Biwood  
       Sep 23, 2021   ❤️ 5
    什么叫喜欢用 @ ,这不是 npm 中的 scope 定义方式吗,通过这帖子发现不少“知其然不知其所以然”的人
    mightofcode
        10
    mightofcode  
       Sep 23, 2021
    yep
    KouShuiYu
        11
    KouShuiYu  
       Sep 23, 2021
    因为这是 npm 推荐的方式 https://docs.npmjs.com/cli/v7/using-npm/scope
    GM
        12
    GM  
    OP
       Sep 24, 2021
    @Biwood 这位兄台,莫非你对所有东西都“知其然且知其所以然”?你从来不碰到疑问?碰到不了解的事情你都不问问题??
    OliveGlaze
        13
    OliveGlaze  
       Sep 24, 2021
    前端工程化,@表示 scope

    至于为啥用 @表示就不清楚了。我只能说 convention 千千万,能找到个常用符号表示就说明这个 convention 是还算是值得一学一用的。
    magicdawn
        14
    magicdawn  
       Sep 24, 2021
    前端还喜欢 包 @版本

    npm i lodash@latest

    就是取 @的 At 意思吧, 然后 @username / orgname 表示用户的, 互联网上大家用惯了, weibo twitter
    alanhe421
        15
    alanhe421  
       Oct 5, 2021
    scope......
    zxCoder
        16
    zxCoder  
       Oct 16, 2021
    还喜欢用 @next
    dany813
        17
    dany813  
       Oct 25, 2021
    @yunyuyuan 这个解释的不错
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2828 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 12:27 · PVG 20:27 · LAX 05:27 · JFK 08:27
    ♥ Do have faith in what you're doing.