简体   繁体   English

如何将反应应用程序创建为服务/包并将其导入另一个应用程序的“package.json”

[英]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

initial file structure and future proposal structure:初始文件结构和未来提案结构:

 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?你有什么想法,不仅是技术上的,还有架构上的,或者任何文档来实现这一点?

Try to use Yarn workspaces, docs here尝试使用 Yarn 工作区,这里的文档

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.

相关问题 在Windows上,package.json中的React Create App Proxy Agent在Windows上运行缓慢 - React create app proxy agent in package.json is slow on Windows 如何在反应应用程序中从 package.json 访问主页? - How is it possible to access homepage from package.json in a react app? 如何在Angular应用程序中暴露package.json - How to expose package.json in angular app 将环境变量从package.json传递到React应用 - Pass environment variable from package.json to React app 如何在不使用 create-react-app 且仅使用我自己的 Webpack 的情况下设置 package.json 进行部署? - How to set the package.json for deployment without using create-react-app and only using my own Webpack? 创建 React App(npm run build) 生成包含不需要的 package.json 内容的 chunk.js 文件 - Create React App(npm run build) generates chunk.js file with unwanted content of package.json 在反应应用程序中将 package.json 上移一个目录 - Move package.json up one dirctory in react app 如何通过 package.json 中的脚本运行应用程序? - How to run app via script in package.json? 如何将我的应用程序中的变量加载到 package.json 中? - How to load a variable form my app into package.json? 反应本地-绝对导入package.json中的别名 - react native - absolute import with alias name in package.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM