[英]How to create react app as a service/package and import it into 'package.json' of another app
Hi currently im working in a monorepo application in react.嗨,目前我正在处理一个 monorepo 应用程序。
What i need is to extract some of its 'components' & 'styling' and create separate modules/packages that live outside of the main project, and import them into package.json
like normal modules.我需要的是提取它的一些“组件”和“样式”并创建位于主项目之外的单独模块/包,然后像普通模块一样将它们导入
package.json
。
myMainproject: \src \components component-styles.scss \button \label \list \item....... \modules \calendar \header \footer \support..... package.json.... // I extract calendar, footer modules calendarService: \src \components component-styles.scss \button \label \list \item....... \modules \calendar..... package.json.... footerService: \src \components component-styles.scss \button \label \list \item....... \modules \footer..... package.json.... // Extract style and create a separate service styleService \src \styles..... package.json.... final 'package.json' of 'myMainproject': ...... "dependencies": { "calendarService": ..., "footerService": .... , "styleService": ..., ..... }
Do you have any ideas, not only technical but architectural also, or any doc to achieve that?你有什么想法,不仅是技术上的,还有架构上的,或者任何文档来实现这一点?
As per the design, for each of the React Module (Calendar, footer and style) that you want to create you'll also need to add an index.js file to the structure.根据设计,对于您要创建的每个 React 模块(日历、页脚和样式),您还需要将 index.js 文件添加到结构中。 You can name the file whatever you want.
您可以随意命名文件。 This is the file that will get executed when your module will get required.
这是在需要您的模块时将执行的文件。
You'll just have to export your components from the index.js file.您只需从 index.js 文件中导出您的组件。 In the package.json file of the separate React modules, you'll have to indicate the JS file that you want to execute when that module is required or imported.
在单独的 React 模块的 package.json 文件中,您必须指出在需要或导入该模块时要执行的 JS 文件。 You do this by providing the name of the file for the main field in package.json
为此,您可以在 package.json 中提供主字段的文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.