【问题标题】:How to install a specific file from the npm packages like from bootstrap only bootstrap.min.css?如何从 npm 包中安装特定文件,例如仅从 bootstrap bootstrap.min.css?
【发布时间】:2019-03-02 22:57:44
【问题描述】:

我在 react 中使用 npm 从 bootstrap 包安装 bootstrap.min.css ,但这让我很好奇,有什么方法可以让我们从 bootstrap 包而不是完整包安装特定文件。 此外,如果我们在我的情况下使用特定文件,则仅 bootstrap.min.css 而不是 bootstrap 包中的其他文件。是否会影响应用的性能。

【问题讨论】:

    标签: node.js reactjs twitter-bootstrap npm


    【解决方案1】:

    如果你知道 Bootstrap 组件的哪一部分,你就可以。

    CSS

    在您的项目中的 scss 文件中导入您需要的 bootstrap/scss/ 中的 scss 文件。 您必须使用 scss 文件格式的样式表。

    // Required
    @import "../node_modules/bootstrap/scss/functions";
    @import "../node_modules/bootstrap/scss/variables";
    @import "../node_modules/bootstrap/scss/mixins";
    // Optional
    @import "../node_modules/bootstrap/scss/reboot";
    ...
    

    参考:https://getbootstrap.com/docs/4.3/getting-started/theming/#importing

    JS

    bootstrap/js/dist/中导入js文件。

    import 'bootstrap/js/dist/util';
    import 'bootstrap/js/dist/alert';
    ...
    

    参考:https://getbootstrap.com/docs/4.3/getting-started/webpack/#importing-javascript

    并且使用特定的组件可以让您拥有紧凑的构建尺寸和更快的加载速度。

    【讨论】:

      猜你喜欢
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 2013-01-18
      • 2017-04-13
      • 2013-07-04
      • 2013-01-10
      相关资源
      最近更新 更多