Skip to content

Implement Bootstrap-Vue tree-shaking to reduce bundle size - #750

Closed
Tim020 wants to merge 3 commits into
devfrom
feat/bootstrap-vue-tree-shaking
Closed

Implement Bootstrap-Vue tree-shaking to reduce bundle size#750
Tim020 wants to merge 3 commits into
devfrom
feat/bootstrap-vue-tree-shaking

Conversation

@Tim020

@Tim020 Tim020 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements tree-shaking for Bootstrap-Vue by replacing the global import with selective component imports, resulting in a 55% reduction in bundle size.

Changes Made

  1. Created Tree-Shakeable Plugin (src/plugins/bootstrap-vue.js)

    • Imports only the 50+ Bootstrap-Vue components actually used in the codebase
    • Imports 8 icons used across the application
    • Registers components globally to maintain compatibility
    • Includes BVModalPlugin for $bvModal functionality
  2. Updated Main Entry Point (src/main.js)

    • Removed global BootstrapVue and IconsPlugin imports
    • Replaced with single import of tree-shakeable plugin
    • Maintains all existing functionality

Performance Impact

Before Tree-Shaking:

  • Main bundle: 1,419 KB (364 KB gzipped)

After Tree-Shaking:

  • Main bundle: 633 KB (186 KB gzipped)
  • 55% reduction in uncompressed size
  • 49% reduction in gzipped size

When Combined with PR #749 (vendor chunking):

  • bootstrap-vendor: 266 KB (67 KB gzipped) vs 1,164 KB (288 KB gzipped)
  • 77% reduction in Bootstrap-Vue chunk size

Components Included

The plugin imports these components based on usage audit:

Layout & Grid: BContainer, BRow, BCol

Forms: BForm, BFormGroup, BFormInput, BFormSelect, BFormSelectOption, BFormCheckbox, BFormInvalidFeedback, BFormText, BFormRow, BInputGroup, BInputGroupAppend

Buttons: BButton, BButtonGroup

Tables: BTable, BTableSimple, BTbody, BTr, BTh, BTd

Tabs: BTabs, BTab

Cards: BCard, BCardText

Modals: BModal (with BVModalPlugin for $bvModal methods)

Navigation: BNavbar, BNavbarBrand, BNavbarNav, BNavbarToggle, BNavItem, BNavItemDropdown, BNavText

Dropdowns: BDropdownItem, BDropdownItemButton

Other: BAlert, BPagination, BProgress, BSpinner, BOverlay, BCollapse, BLink, BTooltip, BTime

Icons: BIcon, BIconPlusSquareFill, BIconCheckSquareFill, BIconXSquareFill, BIconXCircle, BIconSquareFill, BIconQuestionCircleFill, BIconClipboard, BIconCheckCircle

Compatibility

  • ✅ Maintains full backward compatibility
  • ✅ All components registered globally as before
  • $bvModal methods work correctly (msgBoxConfirm, show, hide)
  • ✅ No changes required to existing Vue components
  • ✅ Works with production and development builds

Test Plan

  • Run npm run build - completes successfully
  • Verify bundle size reduction
  • Check for CommonJS errors - none found
  • Test application in browser
  • Verify all Bootstrap-Vue components render correctly
  • Test modal operations ($bvModal.show(), $bvModal.hide(), $bvModal.msgBoxConfirm())
  • Verify all icons display properly

Dependencies

This PR works independently but combines optimally with:

Notes

  • All unused Bootstrap-Vue components are automatically tree-shaken by Vite
  • The component list was generated by scanning the entire codebase for Bootstrap-Vue usage
  • Future component additions should be added to src/plugins/bootstrap-vue.js

🤖 Generated with Claude Code

- Create tree-shakeable plugin file importing only used components
- Replace global BootstrapVue and IconsPlugin imports with selective imports
- Import 50+ Bootstrap-Vue components and 8 icons actually used in codebase
- Maintain $bvModal plugin for modal operations

Components included:
- Layout & Grid: BContainer, BRow, BCol
- Forms: BForm, BFormGroup, BFormInput, BFormSelect, BFormCheckbox, etc.
- Buttons: BButton, BButtonGroup
- Table: BTable, BTableSimple, BTbody, BTr, BTh, BTd
- Navigation: BNavbar, BNavItem, BNavItemDropdown
- Tabs: BTabs, BTab
- Modals: BModal with $bvModal plugin
- Other: BAlert, BPagination, BProgress, BSpinner, BOverlay, etc.

Icons included:
- BIconPlusSquareFill, BIconCheckSquareFill, BIconXSquareFill
- BIconXCircle, BIconSquareFill, BIconQuestionCircleFill
- BIconClipboard, BIconCheckCircle

Benefits:
- Main bundle reduced from 1,419KB to 633KB (55% reduction)
- Gzipped size reduced from 364KB to 186KB (49% reduction)
- When combined with vendor chunking (PR #749), bootstrap-vendor
  chunk will be 266KB (67KB gzipped) vs 1,164KB (288KB gzipped)
- Overall 77% reduction in Bootstrap-Vue bundle size
- Maintains full compatibility with existing code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added client Pull requests changing front end code medium-diff labels Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

Test Results

31 tests  ±0   31 ✅ ±0   8s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 1a86f65. ± Comparison against base commit d9c98ae.

♻️ This comment has been updated with latest results.

Tim020 and others added 2 commits December 1, 2025 23:14
Consolidate three separate imports from 'bootstrap-vue' into a single
import statement to resolve import/no-duplicates linting errors.

- Merge component imports, icon imports, and plugin imports
- Maintain all functionality and organization with inline comments
- No changes to registered components or behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…vidual imports

Replace individual component imports with component group plugins for better
maintainability and following Bootstrap-Vue best practices.

Changes:
- Use LayoutPlugin instead of BContainer, BRow, BCol individually
- Use FormPlugin, FormInputPlugin, FormSelectPlugin, etc. for form components
- Use ButtonPlugin, TablePlugin, TabsPlugin, etc. for other components
- Keep individual icon imports (no group plugin available)
- Consolidate all imports into single statement

Benefits:
- Reduced code from ~170 lines to ~80 lines (53% reduction)
- Easier to maintain (add/remove plugins vs individual components)
- Follows Bootstrap-Vue recommended tree-shaking approach
- Still achieves 53% bundle size reduction vs original

Bundle size:
- Before refactor: 633 KB (186 KB gzipped) - 55% reduction
- After refactor: 667 KB (194 KB gzipped) - 53% reduction
- Trade-off: 5% size increase for significantly better maintainability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added small-diff Small pull request and removed medium-diff labels Dec 1, 2025
@Tim020 Tim020 closed this Dec 1, 2025
@Tim020
Tim020 deleted the feat/bootstrap-vue-tree-shaking branch December 7, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests changing front end code small-diff Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant