【问题标题】:How to install only single component instead of whole package?如何只安装单个组件而不是整个包?
【发布时间】:2019-08-23 18:33:30
【问题描述】:

背景:

您好,我是 react 开发新手,目前正在使用材料 ui 开发 Web 应用程序,我想显示错误和成功消息,我想使用 mdbreact 中的“mdbalert”。 (我知道小吃店,但我觉得它很混乱)

问题:

如何只安装 mdbalert 而不是安装整个 mdbreact 包。

任何建议或提示都会有所帮助。提前致谢。

【问题讨论】:

    标签: reactjs bootstrap-4 warnings material-ui alert


    【解决方案1】:

    据我所知,您将安装整个软件包。然后只根据需要导入 mdbreact。

    如果只需要 mreact 组件的一部分,您可以这样做:

    import React from "react"; // import react and other modules
    import { MDBContainer, MDBAlert } from 'mdbreact'; // import MDBAlert and other components of mbreact
    

    当涉及到生产模式时,Webpack 应该只编译已导入的代码(在本例中为 MDBAlert),而不是整个 mbreact 模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2021-10-18
      相关资源
      最近更新 更多