Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bootstrap 3 to Angular2 webpack based project

I have installed the npm packages for jquery & bootstrap, and then added imports into vendor.ts, but I still don't have any bootstrap styling showing up on the browser.

...
import 'jquery/dist/jquery.js'

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/js/bootstrap.js';
...

I have also tried adding another entry within webpack.common.js, but that didn't help either.

entry: {
    'bootstrap': './node_modules/bootstrap/dist/css/bootstrap.min.css',
    'polyfills': './src/polyfills.ts',
    'vendor': './src/vendor.ts',
    'main': './src/main.browser.ts'
}

Any help would be much appreciated, thanks.

like image 848
Shahzad Avatar asked Jun 15 '16 15:06

Shahzad


1 Answers

You can just use one of the available angular seed projects. For example this one https://github.com/preboot/angular2-webpack

to install bs, just run npm install jquery bootstrap --save

then add the following to vendor.ts

import 'jquery';
import 'bootstrap/dist/js/bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';

and add the following to wepback.common.js

plugins:[
    .....
    ..... ,
    new webpack.ProvidePlugin({   
        jQuery: 'jquery',
        $: 'jquery',
        jquery: 'jquery'
    })
]

For more details check 4th comment from the following link: https://github.com/AngularClass/angular2-webpack-starter/issues/696

worked for me. I used to get complains about jquery not found but it solved my problem.

like image 170
kirqe Avatar answered Nov 07 '22 23:11

kirqe