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

发布于 2025-01-16 01:29:51 字数 606 浏览 4 评论 0原文

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 中。

In package.json, I have:

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

And then run npm install, no error.

In app.js, I try to import the forked package:

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

When I run npm run watch, got the below message:

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

UPDATE:

I compared the original version and forked version in node_modules: Original contains dist folder but forked version don't have. In github, the original one also don't have this folder. And dist is included in .gitignore.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆依然 2025-01-23 01:29:51

据我了解,对于 package.json< /code> GitHub URL,从版本 1.1.65 开始,您可以将 GitHub URL 引用为 foo:user/foo-project,如 见此处

但我仍然建议使用更完整的 URL

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 的缓存用户名/密码或 SSH 的私钥)。

OP Wilson讨论中发表评论dist/ 添加到存储库可能是一个选项,如 在这里
可以在package.json中声明prepare脚本,例如这个

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

正如威尔逊的答案中所述

重要的是,prepare 脚本添加到分叉包中而不是添加到使用该包的项目中。

I understand that, for 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.

But I would still recommend a 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

That way, you control the scheme (HTTPS or SSH) and can check which credentials (cached username/password for HTTPS or private key for SSH) is used.

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

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

As noted in Wilson's answer

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

一场春暖 2025-01-23 01:29:51

最后,我找到了解决方案:

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

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

Finally, I found a solution:

Add "prepare": "npm run lib:build" (or something else depends on the package how to build, can check it in package.json) to scripts of package.json to the forked package. And push to github.

Then, in the project that using the forked package, just keep "package-name": "github:my-github-account/package-name" in package.json and run npm install again. No other changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文