1
1
Using Bootstrap CSS & JS
2
- ========================
2
+ ============================
3
3
4
4
Want to use Bootstrap (or something similar) in your project? No problem!
5
5
First, install it. To be able to customize things further, we'll install
6
- ``bootstrap-sass ``:
6
+ ``bootstrap ``:
7
7
8
8
.. code-block :: terminal
9
9
10
- $ yarn add bootstrap-sass --dev
10
+ $ yarn add bootstrap --dev
11
11
12
- Importing Bootstrap Sass
13
- ------------------------
12
+ Importing Bootstrap Styles
13
+ --------------------------
14
14
15
- Now that ``bootstrap-sass `` lives in your ``node_modules `` directory, you can
15
+ Now that ``bootstrap `` lives in your ``node_modules/ `` directory, you can
16
16
import it from any Sass or JavaScript file. For example, if you already have
17
17
a ``global.scss `` file, import it from there:
18
18
@@ -21,46 +21,18 @@ a ``global.scss`` file, import it from there:
21
21
// assets/css/global.scss
22
22
23
23
// customize some Bootstrap variables
24
- $brand- primary : darken(#428bca , 20%);
24
+ $primary: darken(#428bca , 20%);
25
25
26
26
// the ~ allows you to reference things in node_modules
27
- @import ' ~bootstrap-sass/assets/stylesheets/ bootstrap' ;
27
+ @import " ~bootstrap/scss/ bootstrap" ;
28
28
29
- That's it! This imports the ``node_modules/bootstrap-sass/assets/stylesheets/_bootstrap .scss ``
29
+ That's it! This imports the ``node_modules/bootstrap/scss/bootstrap .scss ``
30
30
file into ``global.scss ``. You can even customize the Bootstrap variables first!
31
31
32
32
.. tip ::
33
33
34
34
If you don't need *all * of Bootstrap's features, you can include specific files
35
- in the ``bootstrap `` directory instead - e.g. ``~bootstrap-sass/assets/stylesheets/bootstrap/alerts ``.
36
-
37
- After including ``bootstrap-sass ``, your Webpack builds might become slow. To fix
38
- this, you can use the ``resolveUrlLoader `` option:
39
-
40
- .. code-block :: diff
41
-
42
- // webpack.config.js
43
- Encore
44
- + .enableSassLoader(function(sassOptions) {}, {
45
- + resolveUrlLoader: false
46
- + })
47
- ;
48
-
49
- This disables the ``resolve-url-loader `` in Webpack, which means that any
50
- ``url() `` paths in your Sass files must now be relative to the original source
51
- entry file instead of whatever file you're inside of (see `Problems with url() `_).
52
- To load Bootstrap, you'll need to override the path to its icons:
53
-
54
- .. code-block :: diff
55
-
56
- // assets/css/global.scss
57
-
58
- + $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
59
-
60
- + // set if you're also including font-awesome
61
- + // $fa-font-path: "~font-awesome/fonts";
62
-
63
- @import '~bootstrap-sass/assets/stylesheets/bootstrap';
35
+ in the ``bootstrap `` directory instead - e.g. ``~bootstrap/scss/alert ``.
64
36
65
37
Importing Bootstrap JavaScript
66
38
------------------------------
@@ -86,16 +58,16 @@ variable. Now, require bootstrap from any of your JavaScript files:
86
58
87
59
.. code-block :: javascript
88
60
89
- // main .js
61
+ // app .js
90
62
91
- var $ = require (' jquery' );
63
+ const $ = require (' jquery' );
92
64
// JS is equivalent to the normal "bootstrap" package
93
65
// no need to set this to a variable, just require it
94
- require (' bootstrap-sass ' );
66
+ require (' bootstrap' );
95
67
96
68
// or you can include specific pieces
97
- // require('bootstrap-sass/javascripts/bootstrap /tooltip');
98
- // require('bootstrap-sass/javascripts/bootstrap /popover');
69
+ // require('bootstrap/js/dist /tooltip');
70
+ // require('bootstrap/js/dist /popover');
99
71
100
72
$ (document ).ready (function () {
101
73
$ (' [data-toggle="popover"]' ).popover ();
@@ -113,5 +85,3 @@ plugins in a similar way:
113
85
// require 2 CSS files needed
114
86
require (' bootstrap-star-rating/css/star-rating.css' );
115
87
require (' bootstrap-star-rating/themes/krajee-svg/theme.css' );
116
-
117
- .. _`Problems with url()` : https://github.com/webpack-contrib/sass-loader#problems-with-url
0 commit comments