mod/bootstrap/vendor/bootstrap/docs/4.0/getting-started/webpack.md in card-1.93.7 vs mod/bootstrap/vendor/bootstrap/docs/4.0/getting-started/webpack.md in card-1.93.8
- old
+ new
@@ -1,9 +1,9 @@
---
layout: docs
title: Webpack
-description: Learn how to include Bootstrap in your project using Webpack 2.
+description: Learn how to include Bootstrap in your project using Webpack 3.
group: getting-started
toc: true
---
## Installing Bootstrap
@@ -24,29 +24,14 @@
import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/dropdown';
...
{% endhighlight %}
-Bootstrap is dependent on [jQuery](https://jquery.com/) and [Popper](https://popper.js.org/), so npm will install them for you if needed. But they must be explicitly provided by webpack. Add the following code to the `plugins` section in your webpack config file:
+Bootstrap is dependent on [jQuery](https://jquery.com/) and [Popper](https://popper.js.org/),
+these are defined as `peerDependencies`, this means that you will have to make sure to add both of them
+to your `package.json` using `npm install --save jquery popper.js`.
-{% highlight js %}
- plugins: [
- ...
- new webpack.ProvidePlugin({
- $: 'jquery',
- jQuery: 'jquery',
- 'window.jQuery': 'jquery',
- Popper: ['popper.js', 'default'],
- // In case you imported plugins individually, you must also require them here:
- Util: "exports-loader?Util!bootstrap/js/dist/util",
- Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
- ...
- })
- ...
- ]
-{% endhighlight %}
-
{% callout warning %}
Notice that if you chose to **import plugins individually**, you must also install [exports-loader](https://github.com/webpack-contrib/exports-loader)
{% endcallout %}
## Importing Styles
@@ -54,10 +39,11 @@
### Importing Precompiled Sass
To enjoy the full potential of Bootstrap and customize it to your needs, use the source files as a part of your project's bundling process.
First, create your own `_custom.scss` and use it to override the [built-in custom variables]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/options/). Then, use your main sass file to import your custom variables, followed by Bootstrap:
+
{% highlight scss %}
@import "custom";
@import "~bootstrap/scss/bootstrap";
{% endhighlight %}
@@ -80,11 +66,11 @@
require('autoprefixer')
];
}
}
}, {
- loader: 'sass-loader' // compiles SASS to CSS
+ loader: 'sass-loader' // compiles Sass to CSS
}]
},
...
{% endhighlight %}
@@ -94,6 +80,19 @@
{% highlight js %}
import 'bootstrap/dist/css/bootstrap.min.css';
{% endhighlight %}
-In this case you may use your existing rule for `css` without any special modifications to webpack config.
+In this case you may use your existing rule for `css` without any special modifications to webpack config except you don't need `sass-loader` just [style-loader](https://github.com/webpack-contrib/style-loader) and [css-loader](https://github.com/webpack-contrib/css-loader).
+
+{% highlight js %}
+ ...
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: ['style-loader', 'css-loader']
+ }
+ ]
+ }
+ ...
+{% endhighlight %}