Use composer dependency for bootstrap library installation

Created on 18 December 2023, about 1 year ago
Updated 16 April 2024, 8 months ago

Problem/Motivation

Installation instructions for the theme require either manual loading steps or inline editing of the composer.json file, which is not the recommended way to use composer (at least as far as I, a site builder, have learned so far).
I believe that some bootstrap themes or modules use twbs/bootstrap to install bootstrap library.
Can this theme's composer setup include a dependency on a separate component that will load the necessary libraries?
(I do not have the skills to provide a patch.)

Steps to reproduce

Attempt to install theme without manually loading files or editing composer.json.

Proposed resolution

Add a dependency on a package that manages the loading of the bootstrap library.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bunthorne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bunthorne
  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Hi,

    Manual installation:

    You can also place the Bootstrap library in the "libraries" folder manually by downloading and extracting it, if you want.

    Composer CLI:

    With composer config you can edit your composer.json with the command line if you do not want to edit your composer.json file manually, see https://getcomposer.org/doc/03-cli.md#config. So, all the changes to do in the composer.json file documented in the README.md can be done with CLI.

    If you want to try with CLI and provide the commands you executed, this can be used to update the README.md, or the installation instructions could be put into drupal.org documentation pages for easier editing by any contributors.

    New dependency:

    I do not want to introduce new dependency to stick as much as possible to Composer and avoid introducing drupalism. If you want you can provide examples of such themes or components that loads the library for evaluation.

  • πŸ‡ΊπŸ‡ΈUnited States bunthorne

    drupal/bootstrap5 loads 2 versions of the bootstrap library directly into the theme's dist/bootstrap5/[version#] path.
    drupal/bootstrap_barrio also has a method of loading the libraries through a composer command as well as using a CDN.

    I'll attempt the method described in the installation instructions to update my composer.json.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Note to myself: update README to not use bower-asset anymore but npm-asset.

  • πŸ‡ΊπŸ‡ΈUnited States bunthorne

    getbootstrap.org offers a method for downloading the libraries with composer:

    Composer

    You can also install and manage Bootstrap’s Sass and JavaScript using Composer:

    composer require twbs/bootstrap:5.3.2

  • Assigned to Grimreaper
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·
  • Issue was unassigned.
  • Status changed to Fixed 11 months ago
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    I have created a MR with updated instructions.

    https://getbootstrap.com/docs/5.3/getting-started/download/#composer: The problem is that the composer package is by default place in the vendor folder, not in the libraries folder.

    I re-tried with stuff like that in composer.json to try to have that moved into the libraries folder without success:

    "installer-paths": {
    ...
                "app/libraries/bootstrap": [
                    "twbs/bootstrap"
                ],
    ...
    
    "installer-paths": {
    ...
                "app/libraries/{$name}": [
                    "twbs/bootstrap",
                    "type:drupal-library",
                    "type:bower-asset",
                    "type:npm-asset"
                ],
    ...
    

    I think this is what I already tried in #3213567: Composer management of the Bootstrap library β†’ .

    https://www.drupal.org/project/bootstrap5: β†’ it has commited the Bootstrap library in multiple versions in its repository, we do not want to do that.

    https://www.drupal.org/project/bootstrap_barrio: β†’
    - for the composer command: I don't see a specific composer command in the repository. The composer.json requires twbs/bootstrap, so same problem like before.
    - in its libraries.yml, the Bootstrap version is hardcoded, same as for https://www.drupal.org/project/bootstrap_library β†’ , with hardcoded list of versions https://git.drupalcode.org/project/bootstrap_library/-/blob/2.0.x/src/Bo...

    So all have hardcoded versions somewhere and/or the composer package is placed into the vendor directory.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡¬πŸ‡§United Kingdom kingfisher64

    Hello,

    I'm struggling to get bootstrap installed/recognised. I installed the libraries module originally and tried:

    composer require twbs/bootstrap:5.3.3 however, listing the directories bootstrap isn't found in libraries/bootstrap.

    I'm getting the following: Could someone offer advice please? Thank you.

    Warning: file_get_contents(libraries/bootstrap/dist/js/bootstrap.bundle.min.js): Failed to open stream: No such file or directory in Drupal\system\Controller\JsAssetController->generateHash() (line 43 of core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php).
    
    Warning: file_get_contents(libraries/bootstrap/dist/js/bootstrap.bundle.min.js): Failed to open stream: No such file or directory in Drupal\Core\Asset\JsCollectionOptimizerLazy->optimizeGroup() (line 175 of core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php).
    
    Warning: file_get_contents(libraries/bootstrap/dist/js/bootstrap.bundle.min.js): Failed to open stream: No such file or directory in Drupal\Core\Asset\JsCollectionOptimizerLazy->generateHash() (line 43 of core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php).
Production build 0.71.5 2024