如何在没有使用NPM或Yarn的情况下使用/导入/安装JavaScript/TypeScript包?

huangapple go评论76阅读模式
英文:

How to use/import/install a Javascript/Typescript Package without NPM or Yarn?

问题

为了提供一些背景信息,我正在通过查看开源GitHub存储库中的“Good first issues”来学习如何处理开源软件。我找到了一个我想要解决的问题,所以我已经下载了一个开源SDK的源代码,并正在对SDK进行更改。

我希望能够通过使用SDK编写另一个简单的应用程序来测试我的更改,但我不确定如何做到这一点。通常情况下,如果我想要使用开发者提供的当前版本的SDK,我会使用Yarn或NPM将包安装到我的应用程序中,然后根据需要使用const package = require("package");import package from "package";导入它。在这一点上,我有点迷茫,因为我想使用我本地版本的包,以确保我所做的更改按预期工作,然后再创建拉取请求。

感谢您提前的建议。

英文:

To give some context, I am learning to work on Open Source software by looking at Good first issues in Open Source GitHub repositories. I have found an issue that I would like to work on and so I have downloaded the source code for an Open Source SDK and I am making changes in the SDK.

I want to be able to test my changes by writing another simple app using the SDK but I am not sure how to do this. Normally, if I were to want to use the current version of the SDK from the developer I would have Yarn or NPM install the package into my app and then import it using either const package = require("package"); or import package from "package" depending on the requirement. This is where I am a little lost as instead of using something that is published I want to use my local version of the package to make sure that the changes I have made work as expected before creating a pull request.

Thank you in advanced for your advice.

答案1

得分: 1

  1. 进入您的 SDK 项目目录并构建可分发版本的 SDK。

  2. 使用 npm packyarn pack 创建一个压缩包,通常是一个 .tgz 文件。

  3. 然后您可以使用 npm install /project-path/your-sdk-version.tgzyarn add file:/project-path/your-sdk-version.tgz

  4. 安装包后,您可以像通常一样导入它到您的包中。

英文:
  1. Go to the directory of your SDK project and build a distributable version of your SDK.

  2. Use npm pack or yarn pack to create a compressed package, usually it is a .tgz file.

  3. Then you can use npm install /project-path/your-sdk-version.tgz or yarn add file:/project-path/your-sdk-version.tgz.

  4. Once the package is installed, you can import it your package like you normally do.

huangapple
  • 本文由 发表于 2023年4月17日 10:15:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031316.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定