How can I add and use bootstrap to an ionic 4 app?

Viewed 21130

I am building an ionic 4 application, and I want to use bootstrap without using the CDN method. I have installed bootstrap with npm install bootstrap.

4 Answers

With Ionic 4, this can be done easily by making use of the angular.json file

open the angular.json file, this can be located at the root of your project

locate the the styles array, add the path to the downloaded bootstrap file

"styles": [
          {
            "input": "src/theme/variables.scss"
          },
          {
            "input": "src/global.scss"
          },
          {
            "input": "node_modules/bootstrap/dist/css/bootstrap.min.css"
          }
        ],

if you wish to make use of bootstrap scripts, add the bootstrap script to the scripts array as well.

Please note: for you to make use of bootstrap scripts, jquery and popper.js are required to be added to your projects as well

  1. create new folder public/css inside ionic app folder.
  2. inside public/css paste copy of bootstrap.min.css.
  3. add "public/css/bootstrap.min.css" string path in angular.json.

*make sure to rebuild your app .>ionic serve

add-bootstrap-to-ionic4_1

add-bootstrap-to-ionic4_2

Just paste the BootstrapCDN into the header of src/index.html.

Related