如何在 Laravel Mix 中导入 Github 的分叉 npm 包?

How to import a forked npm package of Github in Laravel Mix?

package.json中,我有:

"vue-search-select": "github:my-github-account/vue-search-select"

然后运行npm install,没有错误。

app.js中,我尝试导入分叉包:

import { ModelSelect } from 'vue-search-select';

当我 运行 npm run watch 时,收到以下消息:

Module not found: Error: Can't resolve 'vue-search-select'

更新:

我在 node_modules 中比较了原始版本和分叉版本:原始版本包含 dist 文件夹,但分叉版本没有。在github,原来的也没有这个文件夹。 dist 包含在 .gitignore.

我明白,package.json GitHub URL, As of version 1.1.65, you can refer to GitHub URLs as just foo:user/foo-project, as seen here

但我还是会推荐 more complete URL instead:

git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish

这样一来,您就可以控制方案(HTTPS 或 SSH)并可以检查使用了哪些凭据(HTTPS 的缓存 username/password 或 SSH 的私钥)。

OP Wilson comments in the discussion that adding dist/ to the repo could be an option, as .
can be declared in the package.json, such as this one.

  "scripts": {
    "build": "tsc",
    "prepare": "npm run build"
  },

正如威尔逊

中所述

the important thing is that the prepare script is added in forked package, not in the project that using the package.

终于找到了解决办法:

"prepare": "npm run lib:build"(或其他取决于包如何构建,可以在 package.json 中查看)添加到 package.jsonscripts 到分叉包。并推送到 github.

然后,在使用fork包的项目中,只需要在package.json和运行中保留"package-name": "github:my-github-account/package-name" npm install即可。没有其他变化。