Starter template for new building with Bootstrap 4 in npm projects.
Перейти к файлу
Christian Oliff af5bd98085 Create .editorconfig
editorconfig is always useful to have to help ensure consistent code formatting.

This config provides good defaults and is copied from:
https://github.com/twbs/bootstrap/blob/master/.editorconfig
2020-05-27 11:28:57 -07:00
.github/workflows Add basic CI (#9) 2020-05-07 10:48:27 -07:00
assets Add .browserslistrc from v4.4.1. 2020-04-17 08:53:30 +03:00
scss first commit 2020-04-16 13:52:23 -07:00
.browserslistrc Add .browserslistrc from v4.4.1. 2020-04-17 08:53:30 +03:00
.editorconfig Create .editorconfig 2020-05-27 11:28:57 -07:00
.gitattributes Enforce LF 2020-05-06 14:13:38 -07:00
.gitignore first commit 2020-04-16 13:52:23 -07:00
LICENSE.md Create LICENSE.md 2020-04-16 20:04:03 -07:00
README.md Add advanced usage section to readme for optimizing CSS and JS 2020-05-11 12:47:16 -07:00
index.html first commit 2020-04-16 13:52:23 -07:00
package-lock.json Update dependencies 2020-05-06 14:13:52 -07:00
package.json package.json: add a couple of missing properties 2020-05-06 14:14:06 -07:00

README.md

Bootstrap npm starter template

Build Status

This repo is a template for creating new Bootstrap-powered npm projects, maintained by Bootstrap co-author @mdo. You can also use it as your own Bootstrap prototyping sandbox.

Built with Bootstrap v4.4.1 with plans to update for v5.

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.4.1) source files via npm.
  • npm scripts (see package.json) for compiling and autoprefixing Sass, watching for changes, and starting a basic local server.
  • 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.

# 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

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

# Start local server (uses serve)
npm run server

For the most straightforward development, open two Terminal tabs to execute npm run server and npm run watch at the same time.

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, the remaining scripts can be run from your command line with npm run scriptName.

Script Description
start Starts a local server (http://localhost:3000) for development
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-prefix Runs Autoprefixer on the compiled CSS

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.

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.

© @mdo 2020 and licensed MIT.