Yeqela kokuqukethwe okuyinhloko Yeqela ku-docs navigation
in English

I-Webpack nezinqwaba

Funda ukuthi ungafaka kanjani i-Bootstrap kuphrojekthi yakho usebenzisa i-Webpack noma ezinye izinqwaba.

Ifaka i-Bootstrap

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

Ingenisa i-JavaScript

Ngenisa i-JavaScript ye-Bootstrap ngokwengeza lo mugqa endaweni yokungena yohlelo lwakho lokusebenza (ngokuvamile index.jsnoma app.js):

import 'bootstrap';

// or get all of the named exports for further usage
import * as bootstrap from 'bootstrap';

Kungenjalo, uma udinga nje ama-plugin ethu ambalwa, ungangenisa ama- plugin ngawodwana njengoba kudingeka:

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

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

I-Bootstrap incike ku- Popper , ecaciswe peerDependenciesesakhiweni. Lokhu kusho ukuthi kuzofanele uqiniseke ukuthi uyengeza ekusebenziseni package.jsonkwakho npm install @popperjs/core.

Ukungenisa Izitayela

Ingenisa i-Sass Ehlanganisiwe

Ukuze ujabulele amandla aphelele e-Bootstrap futhi uyenze ngendlela oyifisayo ngokwezidingo zakho, sebenzisa amafayela omthombo njengengxenye yenqubo yokuhlanganisa yephrojekthi yakho.

Okokuqala, zenzele eyakho _custom.scssfuthi usebenzise yona ukuze ukhiphe okuguquguqukayo okwakhelwe ngaphakathi . Bese, sebenzisa ifayela lakho eliyinhloko le-Sass ukungenisa okuguquguqukayo kwakho ngokwezifiso, kulandelwa yi-Bootstrap:

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

Ukuze i-Bootstrap ihlanganise, qiniseka ukuthi uyafaka futhi usebenzisa izilayishi ezidingekayo: sass-loader , postcss-loader nge - Autoprefixer . Ngokusetha okuncane, ukulungiselelwa kwepakethi yakho yewebhu kufanele kufake lo mthetho noma 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'
  }]
}
// ...

Ingenisa I-CSS Ehlanganisiwe

Kungenjalo, ungasebenzisa i-CSS ye-Bootstrap elungele ukusetshenziswa ngokumane wengeze lo mugqa endaweni yokungena yephrojekthi yakho:

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

Kulokhu ungasebenzisa umthetho wakho okhona cssngaphandle kokulungiswa okukhethekile kwe-webpack config, ngaphandle kokuthi awudingi sass-loadernje isilayishi sesitayela kanye ne -css-loader .

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