jbsnewmedia/bootstrap-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jbsnewmedia/bootstrap-bundle

Composer 安装命令:

composer require jbsnewmedia/bootstrap-bundle

包简介

Lightweight tools to scaffold and compile Bootstrap SCSS using scssphp. Provides console commands (bootstrap:init, bootstrap:compile) with sensible defaults and vendor-aware import paths.

README 文档

README

Packagist Version Packagist Downloads PHP Version Require Symfony Version License Tests PHP CS Fixer PHPStan Rector codecov

A lightweight Symfony bundle that helps you scaffold and compile Bootstrap SCSS with scssphp. It ships three console commands:

  • bootstrap:init — scaffolds SCSS entry files under assets/scss/.
  • bootstrap:compile — compiles SCSS to CSS (with sensible defaults and vendor‑aware import paths).
  • bootstrap:purge — purges compiled Bootstrap CSS by scanning your templates.

🚀 Features

  • Ready‑to‑use SCSS entries (light and dark)
  • SCSS → CSS via scssphp (pure PHP, no Node required)
  • Writes readable and minified CSS in one run
  • Optional source maps for each output (--source-map)
  • Include paths for vendor/twbs/bootstrap/scss out of the box
  • Purge Bootstrap CSS based on your templates (bootstrap:purge)
  • Clean defaults and sensible paths

⚙️ Requirements

  • PHP 8.2 or higher
  • Symfony 6.4 or 7.x (framework‑bundle, console)
  • Composer
  • Dependencies:
    • twbs/bootstrap (>= 5.3)
    • scssphp/scssphp (^2.0)
    • jbsnewmedia/css-purger (^1.0)

Note: This is a regular Symfony bundle and expects a Symfony kernel (it is auto‑registered).

📦 Installation

Install via Composer:

composer require jbsnewmedia/bootstrap-bundle

If not already present, Composer will install the required packages (twbs/bootstrap, scssphp/scssphp).

📋 Usage

1) Scaffold SCSS entries

Create the default SCSS entry files under assets/scss/:

php bin/console bootstrap:init
# preview without writing files
php bin/console bootstrap:init --dry-run
# overwrite existing files
php bin/console bootstrap:init --force

Files created:

  • assets/scss/bootstrap5-custom.scss
  • assets/scss/bootstrap5-custom-dark.scss

Both entries import Bootstrap after your variable overrides in the correct order.

2) Compile SCSS → CSS

Compile with sensible defaults:

php bin/console bootstrap:compile

Defaults:

  • Input: assets/scss/bootstrap5-custom.scss
  • Outputs:
    • readable CSS → assets/css/bootstrap.css
    • minified CSS → assets/css/bootstrap.min.css

Readable output path can be adjusted via --output-normal.

Generate a source map:

php bin/console bootstrap:compile --source-map

Custom input/output paths:

php bin/console bootstrap:compile path/to/entry.scss public/css/app.css

3) Purge unused Bootstrap CSS (optional)

After compiling, you can purge unused selectors by scanning your templates:

php bin/console bootstrap:purge \
  --input=assets/css/bootstrap.css \
  --output=assets/css/bootstrap-purged.css \
  --templates-dir=templates \
  --include-dir=src \
  --include-file=assets/app.js \
  --selector=collapse --selector=show

🧩 Command reference

bootstrap:init

Scaffolds Bootstrap SCSS entry files.

  • Options:
    • --dry-run — show what would be written without creating files
    • -f, --force — overwrite existing files
  • Alias: boostrap:init (common typo)

Creates the following files in assets/scss/:

  • bootstrap5-custom.scss (light)
  • bootstrap5-custom-dark.scss (dark)

Recommended order inside the files: functions → your variable overrides → Bootstrap import.

bootstrap:compile

Compiles SCSS to CSS using scssphp.

  • Arguments:
    • input (optional) — SCSS entry file; default assets/scss/bootstrap5-custom.scss
    • output (optional) — minified CSS output file; default assets/css/bootstrap.min.css
  • Options:
    • --output-normal, -O — readable (non‑minified) CSS output path; default assets/css/bootstrap.css
    • --source-map — write a .map file next to each CSS output (readable and minified)

Preconfigured include paths (in this order):

  1. vendor/twbs/bootstrap/scss
  2. vendor
  3. assets/scss
  4. assets

This allows imports like:

@import "functions";
@import "variables";
@import "bootstrap";

bootstrap:purge

Purges Bootstrap CSS by scanning your templates and keeping only the selectors that are found.

  • Options:
    • --input, -i — path to input CSS file; default assets/css/bootstrap.css
    • --output, -o — path to write the purged CSS; default assets/css/bootstrap-purged.css
    • --templates-dir — template directories to scan (multiple allowed)
    • --include-dir, -D — additional directories to scan (multiple allowed)
    • --include-file, -F — additional files to scan (multiple allowed)
    • --selector, -S — selectors to always keep (multiple allowed)
    • --readable, -r — generate human‑readable (pretty) CSS output
    • --dry-run — show stats without writing the output file

Source map behavior

When using --source-map, a map is written for each output:

  • Readable CSS: assets/css/bootstrap.css + map assets/css/bootstrap.css.map
  • Minified CSS: assets/css/bootstrap.min.css + map assets/css/bootstrap.min.css.map

Example console output:

Compiled (readable) assets/scss/bootstrap5-custom.scss -> assets/css/bootstrap.css
Source map written: assets/css/bootstrap.css.map
Compiled (minified) assets/scss/bootstrap5-custom.scss -> assets/css/bootstrap.min.css
Source map written: assets/css/bootstrap.min.css.map

If no map is written even though --source-map is set, please check that your SCSS source actually produces output and that the defaults were not overridden.

✍️ Example SCSS

Light (created by bootstrap:init):

// Project-wide Bootstrap configuration
// -------------------------------------------------
// Order matters: load functions first, then override variables,
// then import Bootstrap.

// 1) Bootstrap functions (used in variable calculations)
@import "functions";

// 2) Your variable overrides (omit !default so they actually apply)
$primary: #ff0000;

// 3) Optional: load Bootstrap base variables
@import "variables";

// 4) Import full Bootstrap
@import "bootstrap";

Dark (created by bootstrap:init):

// Dark mode build for Bootstrap
// -------------------------------------------------
// 1) Load Bootstrap functions
@import "functions";

// 2) Set dark-specific variables (adjust examples as needed)
$body-bg: #121212;
$body-color: #e6e6e6;
$primary: #0d6efd;

// Optional: load additional maps/variables from Bootstrap
@import "variables";

// 3) Import full Bootstrap
@import "bootstrap";

🧭 Troubleshooting

  • Input file not found
    • Run php bin/console bootstrap:init to create default entries, or pass your own path to bootstrap:compile.
  • Bootstrap imports not resolved
    • Ensure twbs/bootstrap is installed: composer require twbs/bootstrap.
  • Source map comment is present, but no file is written
    • With the current implementation the map is written after compilation. Check that --source-map is set and your SCSS produces content.
  • scssphp versions
    • This bundle targets scssphp/scssphp ^2.0. If you use another major version, adjust accordingly.

ℹ️ Git information

  • Latest tag: 1.0.2
  • Last commit: ffb3318 — 2026-02-09

📜 License

Licensed under the MIT License. See the LICENSE file for details.

Developed by Juergen Schwind and contributors.

🤝 Contribution

Contributions are welcome! Please fork the repository and open a pull request. For larger changes, consider opening an issue first to discuss your idea.

📫 Contact

For questions or issues, please open an issue or a pull request in the repository.

— Simple Bootstrap SCSS scaffolding and compilation, Composer‑native.

jbsnewmedia/bootstrap-bundle 适用场景与选型建议

jbsnewmedia/bootstrap-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jbsnewmedia/bootstrap-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jbsnewmedia/bootstrap-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 jbsnewmedia/bootstrap-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-24