Skip to content

Instantly share code, notes, and snippets.

@dvgamerr
Last active February 15, 2018 12:17
Show Gist options
  • Save dvgamerr/d6b44f2c4cb3210dd100114078f297dc to your computer and use it in GitHub Desktop.
Save dvgamerr/d6b44f2c4cb3210dd100114078f297dc to your computer and use it in GitHub Desktop.
How to include Bootstrap 3 using webpack

1. Install dependencies

npm install jquery bootstrap-sass bootstrap-loader css-loader node-sass resolve-url-loader sass-loader style-loader url-loader --save-dev

Note: I'm not sure if all dependencies are indeed necessary. I used dependencies from #215 and added others to get it working for Bootstrap 3.

2. Configure Webpack

Edit webpack.common.js to add new loaders and plugin.

To add loaders, edit loaders:[]

{ test: /\.scss$/, loaders: ['style', 'css', 'postcss', 'sass'] },
{ test: /\.(woff2?|ttf|eot|svg)$/, loader: 'url?limit=10000' },
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery' }

To add the jQuery plugin, edit plugins: []

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

3. Import Bootstrap

Edit vendor.browser.ts and add:

import 'jquery';
import 'bootstrap-loader';

Bootstrap should now work. Reload your application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment