Tsibela kumxholo ophambili Tsiba uye kukhangelo lwamaxwebhu
in English

I-Webpack kunye ne-bundlers

Funda indlela yokubandakanya iBootstrap kwiprojekthi yakho usebenzisa iWebpack okanye ezinye iibundle.

Ukufakela i-Bootstrap

Faka i-bootstrap njengemodyuli ye-Node.js usebenzisa i-npm.

Ukuthathwa ngaphandle kweJavaScript

Ngenisa iJavaScript yeBootstrap ngokongeza lo mgca kwindawo yokungena yosetyenziso (ngesiqhelo index.jsokanye app.js):

// You can specify which plugins you need
import { Tooltip, Toast, Popover } from 'bootstrap';

Kungenjalo, ukuba ufuna nje ezimbalwa iiplagi zethu, ungangenisa iiplagi ngokwahlukeneyo njengoko kufuneka:

import Alert from 'bootstrap/js/dist/alert';
...

I-Bootstrap ixhomekeke kwiPopper , echazwe peerDependencieskwipropati. Oku kuthetha ukuba kuya kufuneka uqiniseke ukuba uyongeza package.jsonkusetyenziso lwakho npm install @popperjs/core.

Ukungenisa Izimbo

Ukungeniswa ngaphandle kweSass eQinisekisiweyo

Ukonwabela amandla apheleleyo eBootstrap kwaye uzenzele ngokweemfuno zakho, sebenzisa iifayile zomthombo njengenxalenye yenkqubo yokudibanisa iprojekthi yakho.

Okokuqala, zenzele eyakho _custom.scsskwaye uyisebenzise ukodlula izinto eziguquguqukayo ezakhelwe ngaphakathi . Emva koko, sebenzisa ifayile yakho ephambili yeSass ukungenisa izinto eziguquguqukayo zesiko, zilandelwa yiBootstrap:

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

Ukuze i-Bootstrap ihlanganise, qiniseka ukuba ufaka kwaye usebenzise abalayishi abafunekayo: i-sass-loader , i-postcss-loader nge - Autoprefixer . Ngokucwangciswa okuncinci, uqwalaselo lwakho lwewebhu kufuneka lubandakanye lo mgaqo okanye okufanayo:

// ...
{
  test: /\.(scss)$/,
  use: [{
    // inject CSS to page
    loader: 'style-loader'
  }, {
    // translates CSS into CommonJS modules
    loader: 'css-loader'
  }, {
    // Run postcss actions
    loader: 'postcss-loader',
    options: {
      // `postcssOptions` is needed for postcss 8.x;
      // if you use postcss 7.x skip the key
      postcssOptions: {
        // postcss plugins, can be exported to postcss.config.js
        plugins: function () {
          return [
            require('autoprefixer')
          ];
        }
      }
    }
  }, {
    // compiles Sass to CSS
    loader: 'sass-loader'
  }]
}
// ...

Ukuthathwa ngaphandle kwe-CSS ehlanganisiweyo

Kungenjalo, unokusebenzisa i-Bootstrap esele ilungele ukusebenzisa i-CSS ngokongeza ngokulula lo mgca kwindawo yokungena yeprojekthi yakho:

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

Kulo mzekelo ungasebenzisa umthetho wakho osele cssukho ngaphandle kohlengahlengiso olukhethekileyo kuqwalaselo lwepakethi yewebhu, ngaphandle kokuba awufuni sass-loadernje isimbo sokulayisha kunye ne -css-loader .

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