• This repository has been archived on 30/Mar/2023
  • Stars
    star
    1,232
  • Rank 38,102 (Top 0.8 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Starter template for new building with Bootstrap 4 in npm projects.

Bootstrap npm logo

Bootstrap npm starter template

Create new Bootstrap-powered npm projects in no time.

About

bootstrap-npm-starter is a GitHub template repository for creating new Bootstrap 4 based npm projects, maintained by Bootstrap co-author @mdo. You can also use it as your own Bootstrap prototyping sandbox. For Bootstrap 5 examples, see our new twbs/examples repo.

CI

Repo template

Setup as a starter template, you can easily generate a new GitHub repository. From the repository homepage, click the Use this template button.

What's included

  • Single HTML page (index.html) to demonstrate how to include Bootstrap.
  • Includes Bootstrap (currently using v4.6.2) source files via npm.
  • Includes Bootstrap Icons (v1.10.3), which includes over 1,800 icons available as SVGs and web fonts.
  • npm scripts (see package.json) for compiling and autoprefixing Sass, watching for changes, and starting a local server with live reload.
  • Example stylesheet (scss/starter.scss) highlighting two ways to include and customize Bootstrap.
  • Example JavaScript file (assets/js/starter.js) showing how to import all of Bootstrap, or just the parts you need.

Usage

Be sure to have Node.js installed before proceeding. We recommend only using Node's LTS releases, which is currently at v18.x.

# Clone the repo
git clone https://github.com/twbs/bootstrap-npm-starter
cd bootstrap-npm-starter

# Install dependencies
npm i

# Compile Sass
npm run css-compile

# Start server and watch Sass
npm start

# Watch Sass for changes (uses nodemon)
npm run watch

# Start local server
npm run server

# Watches Sass for changes and starts a local server
npm start

For the most straightforward development, open Terminal and run npm start.

Open http://localhost:3000 to see the page in action.

Scripts

The following npm scripts are available to you in this starter repo. With the exception of npm start and npm test, the remaining scripts can be run from your command line with npm run scriptName.

Script Description
server Starts a local server (http://localhost:3000) for development with live reloads
watch Automatically recompiles CSS as it watches the scss directory for changes
css Runs css-compile and css-prefix
css-compile Compiles source Sass into CSS
css-lint Runs Stylelint against source Sass for code quality
css-prefix Runs Autoprefixer on the compiled CSS
css-purge Runs PurgeCSS to remove CSS that is unused by index.html
test Runs css-lint and css, in sequential order

Advanced usage

Take this starter repository to another level with some built-in addons that you can enable and customize.

Optimizing CSS

Before you start to use tools that remove Bootstrap styling like PurgeCSS, you can make some broad optimizations by only including the stylesheets you think you'll need.

Look to the scss/starter.scss file for your two options of including all of Bootstrap, or a subset of our styles and components. By default we've only imported the stylesheets that Bootstrap requires plus those of the components we're planning to use.

Uncomment specific lines as needed, then recompile to use them.

Optimizing JS

Similar to optimizing CSS, we publish individual scripts for each of our plugins. This allows you to import only what you need, versus the entire bundle and dependencies. For example, if you don't plan on using dropdowns, tooltips, or popovers, you can safely omit the Popper.js depdendency. Bootstrap 4 requires jQuery though, so you won't be able to safely remove that until v5 launches.

See the js/starter.js file for an example of how to import all of Bootstrap's JS or just the individual pieces. By default we've only imported our modal JavaScript since we have no need for anything else.

You can add more options here, or import the entire bootstrap-bundle.min.js file, to get all JavaScript plugins and Popper.js.

PurgeCSS

PurgeCSS is a PostCSS plugin that removes unused CSS based on your site's HTML. It finds rulesets that are unused by your HTML and removes them, ensuring only what's needed is sent to your site's visitors while improving file size and performance.

We've included a single npm script that runs PurgeCSS against our single index.html file to remove unused styles from assets/css/starter.css.

To purge your CSS, run npm run css-purge from the command line. This executes the following:

npm purgecss --css assets/css/starter.css --content index.html --output assets/css/

PurgeCSS is a PostCSS plugin and can be configured to your exact needs with a little extra effort, including additional command line options.

Actions CI

We've included some simple GitHub Actions in this template repo. When you generate your new project from here, you'll have the same tests that run whenever a pull request is created. We've included Actions for the following:

  • Stylelint for your CSS

When your repository is generated, you won't see anything in the Actions tab until you create a new pull request. You can customize these Actions, add new ones, or remove them outright if you wish.

Learn more about GitHub Actions, read the Actions docs, or browse the Actions Marketplace.

Stylelint

Stylelint is included, as is Bootstrap's default Stylelint config, stylelint-config-twbs-bootstrap. This is the same linter configuration we use in the main Bootstrap project. It's run via the npm test command, which is invoked in our ci.yml Actions workflow file.

At the root of the repo, .stylelintignore is used to list files that we ignore when linting and .stylelintrc is where we tell Stylelint to use the Bootstrap config. The former is recommended based on your specific needs, while the latter is required.

Copyright

© @mdo 2020-2023 and licensed MIT.

More Repositories

1

bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
JavaScript
170,512
star
2

ratchet

Build mobile apps with simple HTML, CSS, and JavaScript components.
CSS
14,615
star
3

bootstrap-sass

Official Sass port of Bootstrap 2 and 3.
SCSS
12,589
star
4

icons

Official open source SVG icon library for Bootstrap.
JavaScript
7,335
star
5

rfs

✩ Automates responsive resizing ✩
CSS
3,318
star
6

bootlint

HTML linter for Bootstrap projects
JavaScript
2,397
star
7

bootstrap-rubygem

Bootstrap rubygem for Rails / Sprockets / Hanami / etc
SCSS
2,014
star
8

bootstrap-expo

Beautiful and inspiring uses of Bootstrap.
SCSS
476
star
9

examples

Functional examples of using Bootstrap in common JS frameworks like Webpack, Parcel, Vite, and more!
HTML
297
star
10

blog

Official blog for Bootstrap.
HTML
227
star
11

bootstrap-server

The node server that powers the bootstrap customize page (no longer maintained).
JavaScript
177
star
12

stylelint-config-twbs-bootstrap

Stylelint config for Bootstrap
JavaScript
139
star
13

no-carrier

Tool to auto-close old GitHub issues that were abandoned by their reporter
Scala
131
star
14

release

Bootstrap Release Working Group
114
star
15

rorschach

Bootstrap pull request sanity checker bot
Scala
106
star
16

mq4-hover-shim

A shim for the Media Queries Level 4 `hover` media feature
JavaScript
97
star
17

grunt-bootlint

A Grunt wrapper for Bootlint, the HTML linter for Bootstrap projects
JavaScript
67
star
18

savage

Service to safely run Travis CI tests with heightened permissions on pull requests
Scala
45
star
19

bootstrap-npm

Demo for how to include, customize, and compile Bootstrap's Sass/CSS with npm.
HTML
32
star
20

grunt-css-flip

UNMAINTAINED Grunt plugin for Twitter's css-flip.
JavaScript
24
star
21

gruntworker

Periodically grabs changes, runs build scripts, and pushes built changes back to the Bootstrap git repo
Python
20
star
22

.github

9
star
23

bootlint-server

JavaScript
7
star