7

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.

6
  • what is your webpack config? Commented Jun 15, 2016 at 15:57
  • Did you try to put the bootstrap in the index.html ? Commented Jun 15, 2016 at 15:59
  • @MarkoCen which part of the config do you want to see? Commented Jun 15, 2016 at 16:03
  • @JS_astronauts Yes, I know that will work. But i'm trying to do it using vendor.js. Commented Jun 15, 2016 at 16:04
  • the loaders part, did you add exclude: /node_modules/ in your loader options? Commented Jun 15, 2016 at 16:22

2 Answers 2

15

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I've been looking for a simple solution and finally got one. Thank you so much for this!
For the js bootstrap to work I had to change the order of the ProvidePlugin elements to : [$: 'jquery', jQuery: 'jquery'].
0

I think you need to tell to the Webpack entry point where to find the bootstrap file.

entry: {
    app: './app.ts',
    vendor: [
        'bootstrap/dist/css/bootstrap.css'
    ]
}

1 Comment

I've added my entry object into my question, can you tell me how your answer would work with what I have currently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.