node.js - 如何从 npm 包中安装特定文件,例如仅从 bootstrap bootstrap.min.css?
问题描述
我正在使用 npm 在 react 中使用从 bootstrap 包安装的 bootstrap.min.css ,但这让我很好奇,有什么方法可以让我们从 bootstrap 包而不是完整包中安装特定文件。此外,如果我们在我的情况下使用特定文件,则仅 bootstrap.min.css 而不是 bootstrap 包中的其他文件。是否会影响应用程序的性能。
解决方案
如果你知道 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
将 .js 文件导入bootstrap/js/dist/
.
import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/alert';
...
参考:https ://getbootstrap.com/docs/4.3/getting-started/webpack/#importing-javascript
并且使用特定组件使您具有紧凑的构建尺寸和更快的加载速度。
推荐阅读
- javascript - 使滚动条更新另一个滚动条,反之亦然
- osgi - 哪个版本的 AEM 支持 .cfg.json 配置文件?
- typescript - TypeScript 中是否有“任何枚举类型”的类型?
- c# - 创建一个 DocX 并保存到客户端机器 c#
- javascript - 无效保护不适用于内部 forEach 循环
- ios - 在 Swift 中使用 Codable 解析具有不同键的 JSON
- oauth-2.0 - 谷歌文档人工智能;如何获得不记名令牌?
- sql - 基于 2 列的运行 ID
- kubernetes - 节点没有用于请求的 pod 端口的空闲端口
- vue.js - 如何使 vuetify 工具提示内容可点击?