Source

Wɛbpak

Lan aw fɔ put Bootstrap insay yu prɔjek yuz Wɛbpak 3.

We yu de instɔl di Bootstrap

Instɔl bootstrap as wan Node.js mɔdyul we de yuz npm.

Impɔtant JavaSkript

Impɔt Bootstrap in JavaSkript bay we yu ad dis layn to yu ap in ɛntri pɔynt (bɔku tɛm index.jsɔ app.js):

import 'bootstrap';

Ɔda we de fɔ du dat, yu kin import plɔgin dɛn wan bay wan as nid de:

import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/dropdown';
...

Bootstrap de dipen pan jQuery ɛn Popper , dɛn de difayn dɛn wan ya as peerDependencies, dis min se yu go gɛt fɔ mek shɔ se yu ad dɛn ɔl tu to yu package.jsonyuz npm install --save jquery popper.js.

Notis se if yu pik fɔ import plɔgin dɛn wan bay wan , yu fɔ instɔl exports-loader bak

Impɔt Stayl dɛn

Impɔt Sass we dɛn dɔn kɔmpilayt bifo tɛm

Fɔ ɛnjɔy di ful pɔtnɛshɛl fɔ Bootstrap ɛn kɔstɔmayz am fɔ yu nid, yuz di sɔs fayl dɛn as pat pan yu prɔjek in bɔndling prɔses.

Fɔs, mek yu yon _custom.scssɛn yuz am fɔ ɔvalayz di kɔstɔm vɛriɔbul dɛn we dɛn dɔn bil insay . Dɔn, yuz yu men sass fayl fɔ import yu kɔstɔm vɛriɔbul dɛn, dɔn Bootstrap:

@import "custom";
@import "~bootstrap/scss/bootstrap";

Fɔ mek Bootstrap kɔmpilayt, mek shɔ se yu instɔl ɛn yuz di loda dɛn we yu nid: sass-loader , postcss-loader wit Autoprefixer . Wit minimal setup, yu webpack config shud inklud dis rule or similar:

  ...
  {
    test: /\.(scss)$/,
    use: [{
      loader: 'style-loader', // inject CSS to page
    }, {
      loader: 'css-loader', // translates CSS into CommonJS modules
    }, {
      loader: 'postcss-loader', // Run post css actions
      options: {
        plugins: function () { // post css plugins, can be exported to postcss.config.js
          return [
            require('precss'),
            require('autoprefixer')
          ];
        }
      }
    }, {
      loader: 'sass-loader' // compiles Sass to CSS
    }]
  },
  ...

Impɔt di CSS we dɛn dɔn kɔmpilayt

Ɔda we de fɔ du dat, yu kin yuz Bootstrap in css we rɛdi fɔ yuz bay we yu jɔs ad dis layn to yu prɔjek in ɛntri pɔynt:

import 'bootstrap/dist/css/bootstrap.min.css';

In dis kes yu kin yuz yu rul we de naw fɔ csswitout ɛni spɛshal modifyeshɔn to wɛbpak kɔnfig pas yu nɔ nid sass-loaderjɔs stayl-lɔda ɛn css-lɔda .

  ...
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      }
    ]
  }
  ...