javascript - How Does One Include Bootstrap in Node Project -


i have mean stack project scaffolded using basic npm command. @ moment, bootstrap included using cdn:

link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css') 

my question how can add bootstrap using npm project works same cdn inclusion. in particular, when run

npm install bootstrap 

a boostrap directory created within node_modules. however, if try include bootstrap.css directory, breaks glyphicon fonts. advise on how it?

p.s. pose same question regarding angularjs itself.

you can use browser package manager i.e bower

bower offers generic, unopinionated solution problem of front-end package management, while exposing package dependency model via api can consumed more opinionated build stack. there no system wide dependencies, no dependencies shared between different apps, , dependency tree flat.

if want more knowledge better , reliable read link also.

why not npm

the main difference between npm , bower approach installing package dependencies. npm installs dependencies each package separately, , result makes big package dependency tree (node_modules/grunt/node_modules/glob/node_modules/...), there several version of same package. client-side javascript unacceptable: can't add 2 different version jquery or other library page. bower each package installed once (jquery in bower_components/jquery folder, regardless of how many packages depend on it) , in case of dependency conflict, bower won't install package incompatible 1 that's installed.

bower installation

you simple install packages

syntax

npm install -g bower 

you can refer doc complete information.

for example:

directory structure

project folder   + bower_components      + bootstrap        + dist          + css            + bootstrap.css      + jquery        + jquery.js   + public     + index.html   + app.js 

now can set static path in app.js

app.use(express.static(path.join(__dirname, 'bower_components'))); 

now can use in index.html file

<!doctype html> <html> <head>     <title>{{ title }}</title>     <link rel='stylesheet' href='/bootstrap/dist/css/bootstrap.css' /> </head> <body> {{{ yield }}} </body> <script src="/bootstrap/dist/jquery/jquery.js"></script> </html> 

screenshots

directory structure app.js file enter image description here

normal html file enter image description here


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -