reactjs - Reactjs 从构建的应用程序调用组件/函数
问题描述
我已经构建了一个模块化 Web 应用程序:用户安装核心应用程序并将插件模块(它是一批文件)放到一个文件夹中,核心自动发现它并添加菜单和组件。
实际上,它是 php/jquery/bootstrap,我想用 Reactjs 重写它(用于前端)。不幸的是,我找不到如何使用 Reactjs 保存这个模块化系统。我需要的 :
- 核心将显示页面并调用该页面的某些部分来自插件的组件(如表格的一行)核心将显示
- 一种带有小部件的仪表板,我需要一些小部件,插件核心的一个组件可以显示面板,这个面板是由插件构建的,但插件可以使用核心的一些 JS 来做
- 插件安装后我无法重建 Reactjs 应用程序,唯一的方法是分别构建反应核心应用程序和反应插件应用程序,然后在安装后包含应用程序的构建版本
我搜索但我找不到这种用法的例子,你能帮我吗?
提前感谢您的时间/帮助
解决方案
在标准的 react-build 堆栈中没有干净的方法可以做到这一点。你可以对用户 React 做些什么来避免构建流程。这可能会带来性能问题,并且该过程并不简单,因为 React 社区生态系统基于构建 webpack 过程。
// [...]
<script type="text/babel" charset="utf-8">
// "Import" the components from Reactstrap
// This can be also an array of components stored in an external file
const {Button} = Reactstrap;
// Render a Reactstrap Button element onto root
ReactDOM.render(
<Button color="danger">Hello, world!</Button>,
document.getElementById('root')
);
</script>
// [...]
参考:https ://shinglyu.github.io/web/2018/02/08/minimal-react-js-without-a-build-step-updated.html
推荐阅读
- javascript - javascript搜索没有给出正确的值
- sqlite - 我们什么时候在 Flutter 的表格中使用 Companion?
- python - Python - 不同形状的一维数组广播
- php - 自定义字段在omnipay / paypal laravel中不起作用
- java - 打印出对象
- javascript - 多个信息窗口打开,用复选框切换,infowindow.close 问题
- listview - ScrollController 没有连接到 ListView
- database - sql连接codeigniter数据库报错行号436(wamp server和sql server都在不同的机器上)
- python - 我可以使用 etree.dump() 输出到文件吗?
- node.js - 样式表未解析,因为在严格模式下不允许非 CSS MIME 类型