├── .gitignore ├── LICENSE.md ├── bootstrap-custom.scss ├── index.html ├── package-lock.json ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | **/*.css 3 | **/*.css.map 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 mdo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bootstrap-custom.scss: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap via npm 3 | * Copyright 2018 @mdo 4 | * Licensed MIT 5 | */ 6 | 7 | // Functions, variables, and mixins must come first. 8 | // 9 | // - Variables and mixins are dependant on functions 10 | // - In order to override Sass's default variables, those default variables must 11 | // come first 12 | @import "node_modules/bootstrap/scss/functions"; 13 | @import "node_modules/bootstrap/scss/variables"; 14 | @import "node_modules/bootstrap/scss/mixins"; 15 | 16 | // Override variable defaults 17 | // 18 | // Here is where we customize the variables from Bootstrap's `variables.scss`. 19 | // We copy-pasta variables we need from that source file, remove the `!default` 20 | // flag, and finally change their values. 21 | $body-bg: $gray-200; 22 | $code-color: $danger; 23 | 24 | // @import "node_modules/bootstrap/scss/root"; 25 | @import "node_modules/bootstrap/scss/reboot"; 26 | @import "node_modules/bootstrap/scss/type"; 27 | // @import "node_modules/bootstrap/scss/images"; 28 | @import "node_modules/bootstrap/scss/code"; 29 | @import "node_modules/bootstrap/scss/grid"; 30 | // @import "node_modules/bootstrap/scss/tables"; 31 | // @import "node_modules/bootstrap/scss/forms"; 32 | // @import "node_modules/bootstrap/scss/buttons"; 33 | // @import "node_modules/bootstrap/scss/transitions"; 34 | // @import "node_modules/bootstrap/scss/dropdown"; 35 | // @import "node_modules/bootstrap/scss/button-group"; 36 | // @import "node_modules/bootstrap/scss/input-group"; 37 | // @import "node_modules/bootstrap/scss/custom-forms"; 38 | // @import "node_modules/bootstrap/scss/nav"; 39 | // @import "node_modules/bootstrap/scss/navbar"; 40 | // @import "node_modules/bootstrap/scss/card"; 41 | // @import "node_modules/bootstrap/scss/breadcrumb"; 42 | // @import "node_modules/bootstrap/scss/pagination"; 43 | // @import "node_modules/bootstrap/scss/badge"; 44 | // @import "node_modules/bootstrap/scss/jumbotron"; 45 | // @import "node_modules/bootstrap/scss/alert"; 46 | // @import "node_modules/bootstrap/scss/progress"; 47 | // @import "node_modules/bootstrap/scss/media"; 48 | // @import "node_modules/bootstrap/scss/list-group"; 49 | // @import "node_modules/bootstrap/scss/close"; 50 | // @import "node_modules/bootstrap/scss/modal"; 51 | // @import "node_modules/bootstrap/scss/tooltip"; 52 | // @import "node_modules/bootstrap/scss/popover"; 53 | // @import "node_modules/bootstrap/scss/carousel"; 54 | @import "node_modules/bootstrap/scss/utilities"; 55 | // @import "node_modules/bootstrap/scss/print"; 56 | 57 | html { 58 | // background-color: $gray-200; 59 | } 60 | 61 | @media (min-width: 768px) { 62 | body { 63 | // max-width: 48rem; 64 | // margin-right: auto; 65 | // margin-left: auto; 66 | // background-color: transparent; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |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.
11 |Note: This demo doesn't include compiling Bootstrap's JavaScript.
12 |In addition to our package.json
and some support files, this demo includes two key files:
index.html
— the page you're looking atbootstrap-custom.scss
— a Sass stylesheet where we'll modify and compile our CSSBootstrap'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:
functions
, variables
, and mixins
— useful tools for interacting with and customizing Bootstrap's default styles.reboot
— our opinionated browser normalization styles.type
— our default typography styles.code
— our inline and block code styles.grid
— our layout and grid system styles.utilities
— all our utility classes for rapid prototyping.You may uncomment any of the additional imports, add new imports, or even write new styles.
34 | 35 |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.
bootstrap-npm
.npm start
. This will compile the CSS for the first time.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!