Custom CSS with Bootstrap via npm

This demonstrates building a custom CSS file with Bootstrap's source Sass files, managed via npm. While not a complete solution, this demo highlights how to change default variables, create a custom stylesheet, and choose specific parts of CSS to include.

Note: This demo doesn't include compiling Bootstrap's JavaScript.

Included files

In addition to our package.json and some support files, this demo includes two key files:

Bootstrap's source Sass code is spread across dozens of smaller .scss files. By default, we include every one of these files in what we call our "import stack," a series of @import statements in the source bootstrap.scss files.

To demonstrate how to optionally include Bootstrap piece-by-piece, the full Bootstrap import stack has been commented out in our custom.scss file, save for a handful of components:

You may uncomment any of the additional imports, add new imports, or even write new styles.

Compiling

Built into npm is the ability to run scripts or tasks, like compiling CSS, via the command line. The package.json in any npm package typically includes scripts unique to that project. Here's how to use our this demo's npm scripts to compile a custom Bootstrap build.

  1. From the command line, navigate to this demo's root directory, bootstrap-npm.
  2. When ready, enter npm start. This will compile the CSS for the first time.
  3. Open the index.html file in any browser to see a styled page using your freshly compiled CSS.

To watch the source bootstrap-custom.scss file for changes, enter npm run watch to automatically recompile as necessary.

When using npm start, any changes you make to your custom.scss will automatically cause the Sass file to recompile. Refresh your HTML page to see those changes in action.

Those just getting started with Bootstrap and npm may wish to build on this project's package.json by adding new dependencies and scripts. Please do!