您當前的位置:首頁 > 歷史

Scratch3.0二次開發|補充-1:npm link 使用

作者:由 牛奶嗎啡 發表于 歷史時間:2020-03-07

easy-scratch-gui 在構建的時候,使用了 npm link,需要額外說明一下

擴充套件閱讀:npm-link:

https://

docs。npmjs。com/cli/link

。html

https://

docs。npmjs。com/misc/con

fig

https://

github。com/atian25/blog

/issues/17

https://www。

jianshu。com/p/aaa7db89a

5b2

這是一個很有用的命令

尤其是有專案依賴的時候

或者要使用 js lib 工程的時候

我簡述這個命令做了什麼:

-1 使用案例:

npm link (in package dir)

npm link [<@scope>/][@

-2 npm link (in package dir)

在全域性的 node_modules 資料夾中,建立一個 “類似快捷方式” 的 symlink

這個快捷方式指向:package dir 這個模組

檢視全域性的 node_modules 資料夾路徑:npm -c

npm link in a package folder will create a symlink in the global folder{prefix}/lib/node_modules/ that links to the package where the npm link command was executed。 (see npm-config for the value of prefix)。

-3 npm link [<@scope>/][@

在當前目錄,建立一個快捷方式

可以在專案中直接使用這個模組

create a symbolic link from globally-installed package-name to node_modules/ of the current folder。

-4 全域性 unlink 那個模組

在模組的根目錄,執行:npm unlink

-5 在某個專案 unlink 那個模組

在專案的根目錄,執行:npm unlink pkg-name

-6 本質上就是:全域性 + 快捷方式,因此改動其中一處的程式碼,所有都會變

其實修改的是一個

-7 注意:

一直用的都是 pack-name,而不是資料夾名字

link/unlink 可能需要 sudo

-8 可以看到,在 scratch-blocks 模組的根目錄執行 npm link 後,

在全域性 node_modules 中會多一個快捷方式

-9 可以看到,在 bell-scratch 專案的根目錄執行:npm link scratch-vm scratch-blocks 後,

模組資料夾中就多了兩個快捷方式 vm 和 blocks

Scratch3.0二次開發|補充-1:npm link 使用

Scratch3.0二次開發|補充-1:npm link 使用

標簽: npm  LINK  快捷方式  package  模組