in English

Webpack

Funda indlela yokubandakanya iBootstrap kwiprojekthi yakho usebenzisa iWebpack.

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):

import 'bootstrap';

Kungenjalo, ungangenisa ii- plugins nganye nganye njengoko kufuneka:

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

I-Bootstrap ixhomekeke kwijQuery kunye nePopper , echazwe peerDependencieskwipropati; oku kuthetha ukuba kuya kufuneka uqiniseke ukuba uzongeza zombini ekusebenziseni package.jsonkwakho npm install --save jquery popper.js.

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 iqokelele, qiniseka ukuba ufaka kwaye usebenzise abalayishi abafunekayo: i-sass-loader , i-postcss-loader nge - Autoprefixer . Ngokuseta okuncinci, uqwalaselo lwakho lwepakethi yewebhu kufuneka lubandakanye lo mgaqo okanye okufanayo:

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

Ukuthathwa ngaphandle kwe-CSS ehlanganisiweyo

Kungenjalo, ungasebenzisa 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']
    }
  ]
}
...