英文:
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
-
进入您的 SDK 项目目录并构建可分发版本的 SDK。
-
使用
npm pack
或yarn pack
创建一个压缩包,通常是一个 .tgz 文件。 -
然后您可以使用
npm install /project-path/your-sdk-version.tgz
或yarn add file:/project-path/your-sdk-version.tgz
。 -
安装包后,您可以像通常一样导入它到您的包中。
英文:
-
Go to the directory of your SDK project and build a distributable version of your SDK.
-
Use
npm pack
oryarn pack
to create a compressed package, usually it is a .tgz file. -
Then you can use
npm install /project-path/your-sdk-version.tgz
oryarn add file:/project-path/your-sdk-version.tgz
. -
Once the package is installed, you can import it your package like you normally do.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论