Webpack import bootstrap .js and .css Webpack import bootstrap .js and .css reactjs reactjs

Webpack import bootstrap .js and .css


You need to do the following things to make it work:

  1. In your webpack config file, resolve section, make sure your bootstrap css file path is included.

As an example:

var bootstrapPath = path.join(    __dirname,    'development/bower_components/bootstrap/dist/css');

Then in your webpack config object:

resolve: {    alias: {        jquery: path.join(__dirname, 'development/bower_components/jquery/jquery')    },    root: srcPath,    extensions: ['', '.js', '.css'],    modulesDirectories: ['node_modules', srcPath, commonStylePath, bootstrapPath]}
  1. Make sure you have style loader and css loader. E.g.loaders:[{ test: /\.css$/, loader: "style-loader!css-loader" }]
  2. Use it in your js filerequire('bootstrap.min.css');


Just use the less plugin and declare them properly...

// Webpack file{  test: /\.less$/,  loader: "style-loader!css-loader!less-loader"},// I have to add the regex .*? because some of the files are named like... fontello.woff2?952370{  test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?.*)?$/,  loader: 'url?limit=50000'}// Less file@import '~bootstrap/less/bootstrap';

I am still working on the JS but I will let you know soon :-)