[英]How to copy npm package files to my local project?
It could be a duplicate question, but I could not find the answer I wanted, no matter how I tried to find it. 它可能是一个重复的问题,但是无论我如何尝试都找不到我想要的答案。 So, I ask.
所以,我问。
What I wanted: 我想要的是:
Move the file in node_modules to my project, so that I can use it while editing the file 将node_modules中的文件移动到我的项目中,以便在编辑文件时可以使用它
First try: 第一次尝试:
Moved the file I wanted to edit And only modify the import path for that file 移动了我要编辑的文件,仅修改了该文件的导入路径
result: 结果:
weird: 奇怪的:
All modified paths are correct 所有修改的路径均正确
ie I can move to that imported file through that path in the IDE. 即我可以通过IDE中的该路径移动到该导入的文件。
Example repo: 回购示例:
https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1 Especially: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1/src/components/editableText https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1特别是: https : //github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1/src/components/editableText
Second try: 第二次尝试:
I moved all of the files imported as well as the file I want to modify, into the project. 我将所有导入的文件以及要修改的文件都移到了项目中。
result: 结果:
My opinion: It seems to be related to Typescript or commonjs. 我的看法:它似乎与Typescript或commonjs有关。 But I do not know how to make it work.
但是我不知道如何使它工作。
Example repo: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2 Especially: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2/src/components/list/editableText/components/editable-text 回购示例: https : //github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2特别是: https : //github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2/src/components/list/editableText/components/可编辑文字
If anyone knows how to solve the problem, I would be very grateful. 如果有人知道如何解决问题,我将不胜感激。
Here are a few options for you: 以下是您的一些选择:
Solution 1: You could manually monkey-patch the module in question: 解决方案1:您可以手动猴子修补有问题的模块:
Here is how to do it (general approach): 这是操作方法(一般方法):
Create a new file named ModifiedEditableText.tsx
创建一个名为
ModifiedEditableText.tsx
的新文件
Then in that file: 然后在该文件中:
import { EditableText } from "@blueprintjs/core";
const newModule = {};
// First, copy over all the fields from the original module
for (let fieldName in EditableText) {
newModule[fieldName] = EditableText[fieldName];
}
// Then write new implementations of any function you want to change
newModule.function1 = function(arg, arg2, arg3) {
// new function implementation
// To call the original function do:
EditableText.function1();
}
export default newModule;
Solution 2: Fork the module, do your change, submit a PR and hope that it is merged (probably not gonna happen) 解决方案2:分叉模块,进行更改,提交PR,并希望将其合并(可能不会发生)
Solution 3: Fork the module, do your change(s) and import that module in your code instead of the official library 解决方案3:分叉模块,进行更改,然后将该模块导入代码中,而不是官方库中
Solution 4: Use a library to monkey patch your component, here are some examples of such libraries: 解决方案4:使用库来修补您的组件,以下是此类库的一些示例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.