Install Parcel

Install Parcel Bundler.

Install Bootstrap

Install bootstrap as a Node.js module using npm.

Bootstrap depends on Popper, which is specified in the peerDependencies property. This means that you will have to make sure to add both of them to your package.json using npm install @popperjs/core.

When all will be completed, your project will be structured like this:

  1. project-name/
  2. ├── build/
  3. ├── node_modules/
  4. └── bootstrap/
  5. └── popper.js/
  6. ├── scss/
  7. └── custom.scss
  8. ├── src/
  9. └── index.html
  10. └── index.js
  11. └── package.json

Importing JavaScript

Import Bootstrap’s JavaScript in your app’s entry point (usually src/index.js). You can import all our plugins in one file or separately if you require only a subset of them.

  1. // Import all plugins
  2. import * as bootstrap from 'bootstrap';
  3. // Or import only needed plugins
  4. import { Tooltip as Tooltip, Toast as Toast, Popover as Popover } from 'bootstrap';
  5. // Or import just one
  6. import Alert as Alert from '../node_modules/bootstrap/js/dist/alert';

Importing CSS

To utilize the full potential of Bootstrap and customize it to your needs, use the source files as a part of your project’s bundling process.

Create your own scss/custom.scss to import Bootstrap’s Sass files and then override the built-in custom variables.

Build app

Include src/index.js before the closing </body> tag.

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. </head>
  7. <body>
  8. <script src="./index.js"></script>
  9. </body>
  10. </html>

Edit package.json

Add dev and build scripts in your package.json file.

  1. "scripts": {
  2. "dev": "parcel ./src/index.html",
  3. "prebuild": "npx rimraf build",
  4. "build": "parcel build --public-url ./ ./src/index.html --experimental-scope-hoisting --out-dir build"
  5. }

Run dev script

Your app will be accessible at http://127.0.0.1:1234.

  1. npm run dev

Build app files

Built files are in the build/ folder.

  1. npm run build