bootstrap-ui icon indicating copy to clipboard operation
bootstrap-ui copied to clipboard

Suggest installing Bootstrap assets via composer

Open mehov opened this issue 1 year ago • 7 comments

FriendsOfCake/bootstrap-ui does not come with Bootstrap itself, so we need to install the whole thing separately.

Right now the recommended way to do that seems to be via npm, either using bin/cake bootstrap install or manually:

Consider recommending getting Bootstrap from composer. I think that's much faster, more native to PHP and does not require npm to be available.

composer require twbs/bootstrap:5.3.3
composer require twbs/bootstrap-icons

(I had to install twbs/bootstrap-icons separately because twbs/bootstrap doesn't seem to contain the font directory.)

Link your application webroot to where Bootstrap files are actually located:

mkdir ./webroot/bootstrap_u_i
ln -s ../../vendor/twbs/bootstrap/dist/css ./webroot/bootstrap_u_i/css
ln -s ../../vendor/twbs/bootstrap/dist/js ./webroot/bootstrap_u_i/js
ln -s ../../vendor/twbs/bootstrap-icons/font ./webroot/bootstrap_u_i/font

The default FriendsOfCake/bootstrap-ui layout expects the files to be available under /bootstrap_u_i, so by symlinking the path like that, it picks almost everything up right away automatically.

mehov avatar Nov 11 '24 17:11 mehov

Only /bootstrap_u_i/js/popper.js didn't get picked up automatically because it never gets compiled like I assume it would under npm.

mehov avatar Nov 11 '24 17:11 mehov

I would prefer to have Bootstrap included using composer instead of npm as well.

The ./webroot/bootstrap_u_i folder should be created by bin/cake plugin assets symlink, but maybe the other symlinks could be done in the InstallCommand.php

umer936 avatar Nov 12 '24 15:11 umer936

FriendsOfCake/bootstrap-ui does not come with Bootstrap itself, so we need to install the whole thing separately.

That's intentional. It gives the freedom to users to manage the bootstrap assets as they wish.

As for the use of npm, it's because that's what was contributed by the community. I am fine if the install commands where updated to add bootstrap as a composer dependency of the app itself. I don't want to add bootstrap as a direct dependency of the plugin, as it would then install it unnecessarily even if someone is managing their assets through npm.

ADmad avatar Nov 24 '24 07:11 ADmad

Sure, I never meant to suggest to actually automatically install Bootstrap. Seems I wasn't clear enough, sorry about that.

What I was suggesting it to tell people how to quickly get it with composer (and that they can actually do it) right next to where you already tell them how to install it with npm. In other words, just edit the docs.

I can see how some can not think of composer as an option, and not wanting to deal with npm, will proceed to download the zip.

mehov avatar Nov 25 '24 12:11 mehov

While I am not good enough with phrasing things when writing the docs to suggest a PR, I did paste the commands that worked for me above.

mehov avatar Nov 25 '24 12:11 mehov

Should just need a command for "install from npm, composer, or zip", which would do the associated download and make the symlinks

If no one gets to it in a month+, I'll probably do it.

umer936 avatar Nov 25 '24 12:11 umer936

Here's my composer.json:

...

        "twbs/bootstrap": "^5",
        "twbs/bootstrap-icons": "@stable"
...

        "post-update-cmd": [
            "bin/cake plugin assets symlink",
            "rm -rf ./webroot/bootstrap_u_i/css && ln -s ../../../twbs/bootstrap/dist/css ./webroot/bootstrap_u_i/css",
            "rm -rf ./webroot/bootstrap_u_i/js && ln -s ../../../twbs/bootstrap/dist/js ./webroot/bootstrap_u_i/js",
            "rm -rf ./webroot/bootstrap_u_i/font/font && ln -s ../../../../twbs/bootstrap-icons/font ./webroot/bootstrap_u_i/font/font"
        ],
...

umer936 avatar Feb 24 '25 22:02 umer936