首页 > 解决方案 > Reactjs 从构建的应用程序调用组件/函数

问题描述

我已经构建了一个模块化 Web 应用程序:用户安装核心应用程序并将插件模块(它是一批文件)放到一个文件夹中,核心自动发现它并添加菜单和组件。

实际上,它是 php/jquery/bootstrap,我想用 Reactjs 重写它(用于前端)。不幸的是,我找不到如何使用 Reactjs 保存这个模块化系统。我需要的 :

我搜索但我找不到这种用法的例子,你能帮我吗?

提前感谢您的时间/帮助

标签: 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


推荐阅读