用途:用 npm 与命令行工具搭建 Bootstrap 6 起始项目,将 Sass 编译为 CSS,不使用 JavaScript 打包器,Bootstrap 预构建的 JS bundle 通过 script 标签直接加载。需要 Node.js 与终端操作基础。
主要能力:通过 npm 安装 Bootstrap 及可选依赖,用 Sass 编译源码并配合 PostCSS/Autoprefixer 后处理,提供 watch、serve、lint 等本地开发脚本,并可通过 with () 定制 token。
使用方式:创建项目并执行 npm init -y;安装 Bootstrap 与可选 peer 依赖(@floating-ui/dom、vanilla-calendar-pro),再安装 autoprefixer、postcss、postcss-cli、sass 及 nodemon、npm-run-all、sirv-cli、stylelint、stylelint-config-twbs-bootstrap。建立 css、scss 目录及 index.html、postcss.config.js、stylelint.config.mjs。package.json 中加入脚本,注意 Sass 需 --load-path=node_modules。在 scss/styles.scss 中使用 @use "bootstrap/scss/bootstrap",可用 with () 覆盖 $root-tokens 等 token 映射。运行 npm start 启动,访问 http://localhost:8080 验证。
适用场景:需要精细定制 Bootstrap Sass、不引入模块打包器的项目。
限制:Bootstrap 6 需要支持 oklch() 与 color-mix() 的浏览器;自行编译源码时 token 名称不加 --bs- 前缀;仅导入所用部分时参考 twbs/examples 的 sass-js 项目。详细配置、代码与命令请以原始资料为准。