Skip to content

Update bootstrap.rst #9918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 26 additions & 44 deletions frontend/encore/bootstrap.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
Using Bootstrap CSS & JS
========================
Using Bootstrap 4 CSS & JS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change and remove the 4 version number. This article will be perpetually updated when new versions of Bootstrap are published, so there's no need to update the title.

============================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be reverted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c90f20a. The other issues were fixed in 6b732a6. Thanks for reporting.


Want to use Bootstrap (or something similar) in your project? No problem!
First, install it. To be able to customize things further, we'll install
``bootstrap-sass``:
``bootstrap`` and popper.js:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change because the article is about Bootstrap, so we don't want to install other libraries. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I delete popper.js but bootstrap 4 need it to work with tooltips. (Yarn and nmp say to add this dependancie when we install bootstrap so is ok)


.. code-block:: terminal

$ yarn add bootstrap-sass --dev
$ yarn add bootstrap popper.js --dev

Importing Bootstrap Sass
or if you prefer to use npm:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to use yarn in the Symfony Docs. This is of course a decision that can be debated and changed. But meanwhile we can't change individual articles. So, let's remove this change about "npm" and the other one later in this article.


.. code-block:: terminal

$ npm install bootstrap popper.js --save-dev

Importing Bootstrap 4
------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be shortened.


Now that ``bootstrap-sass`` lives in your ``node_modules`` directory, you can
Now that ``bootstrap`` lives in your ``node_modules`` directory, you can
import it from any Sass or JavaScript file. For example, if you already have
a ``global.scss`` file, import it from there:

Expand All @@ -21,55 +27,31 @@ a ``global.scss`` file, import it from there:
// assets/css/global.scss

// customize some Bootstrap variables
$brand-primary: darken(#428bca, 20%);
$primary: darken(#428bca, 20%);

// the ~ allows you to reference things in node_modules
@import '~bootstrap-sass/assets/stylesheets/bootstrap';
@import "~bootstrap/scss/bootstrap";

That's it! This imports the ``node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss``
That's it! This imports the ``node_modules/bootstrap/scss/bootstrap.scss``
file into ``global.scss``. You can even customize the Bootstrap variables first!

.. tip::

If you don't need *all* of Bootstrap's features, you can include specific files
in the ``bootstrap`` directory instead - e.g. ``~bootstrap-sass/assets/stylesheets/bootstrap/alerts``.

After including ``bootstrap-sass``, your Webpack builds might become slow. To fix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking, why did you remove this explanation about resolveUrlLoader? Is it no longer needed in Bootstrap 4? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I delete this because now on the scss file from bootstrap, we don't need to change the path from the webfont etc, so WebPack work realy fine now... i'm doing some test but for me isn't necessary anymore.

this, you can use the ``resolveUrlLoader`` option:

.. code-block:: diff

// webpack.config.js
Encore
+ .enableSassLoader(function(sassOptions) {}, {
+ resolveUrlLoader: false
+ })
;

This disables the ``resolve-url-loader`` in Webpack, which means that any
``url()`` paths in your Sass files must now be relative to the original source
entry file instead of whatever file you're inside of (see `Problems with url()`_).
To load Bootstrap, you'll need to override the path to its icons:

.. code-block:: diff

// assets/css/global.scss

+ $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";

+ // set if you're also including font-awesome
+ // $fa-font-path: "~font-awesome/fonts";

@import '~bootstrap-sass/assets/stylesheets/bootstrap';
in the ``bootstrap`` directory instead - e.g. ``~bootstrap/scss/alert``.

Importing Bootstrap JavaScript
------------------------------
---------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be reverted.


Bootstrap JavaScript requires jQuery, so make sure you have this installed:

.. code-block:: terminal

$ yarn add jquery --dev

.. code-block:: terminal

$ npm install jquery --save-dev

Next, make sure to call ``.autoProvidejQuery()`` in your ``webpack.config.js`` file:

Expand All @@ -86,16 +68,16 @@ variable. Now, require bootstrap from any of your JavaScript files:

.. code-block:: javascript

// main.js
// app.js

var $ = require('jquery');
const $ = require('jquery');
// JS is equivalent to the normal "bootstrap" package
// no need to set this to a variable, just require it
require('bootstrap-sass');
require('bootstrap');

// or you can include specific pieces
// require('bootstrap-sass/javascripts/bootstrap/tooltip');
// require('bootstrap-sass/javascripts/bootstrap/popover');
// require('bootstrap/js/dist/tooltip');
// require('bootstrap/js/dist/popover');

$(document).ready(function() {
$('[data-toggle="popover"]').popover();
Expand Down