如何从NPM软件包中安装特定文件,例如Bootstrap仅Bootstrap.min.css



我正在使用bootstrap.min.css使用react中的npm从bootstrap软件包安装的bootstrap.css,但它使我感到好奇,以便我们可以从bootstrap安装特定文件软件包而不是完整包装。此外,如果我们在我的情况下使用特定文件,则只有Bootstrap.min.css而不是Bootstrap软件包中的其他文件。它会影响应用程序的性能吗?

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

CSS

您在项目中需要在 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

使用特定的组件使您具有紧凑的构建尺寸,并且加载速度更快。

相关内容

最新更新