简体   繁体   English

React 新手:如何编辑通过 npm 安装的组件?

[英]Newbie in React: how to edit a component that was installed via npm?

I've followed the instructions in this URL ( https://github.com/react-component/calendar ) to install a component app in my dependencies.我已按照此 URL ( https://github.com/react-component/calendar ) 中的说明在我的依赖项中安装组件应用程序。 I have succesfully installed it, imported it and it is visible and usable in my web app.我已成功安装并导入它,它在我的网络应用程序中可见且可用。

npm install rc-calendar
import Calendar from 'rc-calendar';
<Calendar />

However, I can't seem to edit it or find a 'Calendar.js' file to make changes to it?但是,我似乎无法编辑它或找到“Calendar.js”文件来对其进行更改? I'm able to see it in my package.json file but not more than that我可以在我的 package.json 文件中看到它,但仅此而已

You'll find the source files in your node_modules folder in your project.您将在项目的 node_modules 文件夹中找到源文件。 But I would not edit them there.但我不会在那里编辑它们。 If you want to use that plugin as a starting point and edit it from there, I recommend downloading the source files from the github repo and including it in your project as a regular.js file / regular component.如果您想将该插件用作起点并从那里对其进行编辑,我建议您从 github 存储库下载源文件并将其作为 regular.js 文件/常规组件包含在您的项目中。 Then you can edit from there.然后你可以从那里编辑。 It looks like that plugin has many files that are written in typescript.看起来那个插件有很多用打字稿写的文件。

TL;DR You can, but you shouldn't. TL;DR 你可以,但你不应该。

When you use npm it's supposed that you don't change those packages, what you can do is create your own version.当您使用 npm 时,假设您不更改这些包,您可以做的是创建您自己的版本。 If you want to find the source code, some packages come with it, you'll find it in: <project folder>/node_modules/rc-calendar .如果你想找到源代码,一些包附带它,你会在以下位置找到它: <project folder>/node_modules/rc-calendar

The typical convention is to not edit packages installed via npm.典型的惯例是不编辑通过 npm 安装的包。 However, you can clone the package repo and include it in your project.但是,您可以克隆包存储库并将其包含在您的项目中。 There, you can do what ever you want.在那里,你可以做任何你想做的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM