From 5e5f0aa955d86743a14531bed98501b59140ab1f Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 11 Oct 2022 18:18:57 +0000 Subject: update composer libs --- .../content/docs/5.2/getting-started/webpack.md | 90 +++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) (limited to 'vendor/twbs/bootstrap/site/content/docs/5.2/getting-started/webpack.md') diff --git a/vendor/twbs/bootstrap/site/content/docs/5.2/getting-started/webpack.md b/vendor/twbs/bootstrap/site/content/docs/5.2/getting-started/webpack.md index e314ecf6a..870e070e3 100644 --- a/vendor/twbs/bootstrap/site/content/docs/5.2/getting-started/webpack.md +++ b/vendor/twbs/bootstrap/site/content/docs/5.2/getting-started/webpack.md @@ -4,6 +4,7 @@ title: "Bootstrap & Webpack" description: The official guide for how to include and bundle Bootstrap's CSS and JavaScript in your project using Webpack. group: getting-started toc: true +thumbnail: guides/bootstrap-webpack@2x.png --- @@ -74,7 +75,7 @@ At this point, everything is in the right place, but Webpack won't work because With dependencies installed and our project folder ready for us to start coding, we can now configure Webpack and run our project locally. -1. **Open `webpack.config.js` in your editor.** Since it's blank, we'll need to add some boilerplate config to it so we can start our server. This part of the config tells Webpack were to look for our project's JavaScript, where to output the compiled code to (`dist`), and how the development server should behave (pulling from the `dist` folder with hot reload). +1. **Open `webpack.config.js` in your editor.** Since it's blank, we'll need to add some boilerplate config to it so we can start our server. This part of the config tells Webpack where to look for our project's JavaScript, where to output the compiled code to (`dist`), and how the development server should behave (pulling from the `dist` folder with hot reload). ```js const path = require('path') @@ -229,6 +230,93 @@ Importing Bootstrap into Webpack requires the loaders we installed in the first Now you can start adding any Bootstrap components you want to use. Be sure to [check out the complete Webpack example project](https://github.com/twbs/examples/tree/main/webpack) for how to include additional custom Sass and optimize your build by importing only the parts of Bootstrap's CSS and JS that you need. +## Production optimizations + +Depending on your setup, you may want to implement some additional security and speed optimizations useful for running the project in production. Note that these optimizations are not applied on [the Webpack example project](https://github.com/twbs/examples/tree/main/webpack) and are up to you to implement. + +### Extracting CSS + +The `style-loader` we configured above conveniently emits CSS into the bundle so that manually loading a CSS file in `dist/index.html` isn't necessary. This approach may not work with a strict Content Security Policy, however, and it may become a bottleneck in your application due to the large bundle size. + +To separate the CSS so that we can load it directly from `dist/index.html`, use the `mini-css-extract-loader` Webpack plugin. + +First, install the plugin: + +```sh +npm install --save-dev mini-css-extract-plugin +``` + +Then instantiate and use the plugin in the Webpack configuration: + +```diff +--- a/webpack/webpack.config.js ++++ b/webpack/webpack.config.js +@@ -1,8 +1,10 @@ ++const miniCssExtractPlugin = require('mini-css-extract-plugin') + const path = require('path') + + module.exports = { + mode: 'development', + entry: './src/js/main.js', ++ plugins: [new miniCssExtractPlugin()], + output: { + filename: "main.js", + path: path.resolve(__dirname, "dist"), +@@ -18,8 +20,8 @@ module.exports = { + test: /\.(scss)$/, + use: [ + { +- // Adds CSS to the DOM by injecting a `