Mafere na isi ọdịnaya Gaa na ntugharị docs
in English

Akpa webụsaịtị na ngwugwu

Mụta otu esi etinye Bootstrap n'ọrụ gị site na iji Webpack ma ọ bụ ngwugwu ndị ọzọ.

Ịwụnye Bootstrap

Wụnye bootstrap dị ka modul Node.js site na iji npm.

Na-ebubata JavaScript

Bubata JavaScript nke Bootstrap site na ịgbakwunye ahịrị a na ntinye ngwa gị (na-emekarị index.jsma ọ bụ app.js):

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

N'aka nke ọzọ, ọ bụrụ na ị chọrọ naanị ole na ole n'ime plugins anyị, ị nwere ike ibubata plugins n'otu n'otu dị ka achọrọ:

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

Bootstrap na-adabere na Popper , nke akọwapụtara na ihe peerDependenciesonwunwe. Nke a pụtara na ị ga-enwerịrị ike itinye ya na package.jsoniji npm install @popperjs/core.

Ụdị mbubata

Na-ebubata Sass agbakọtagoro

Iji kporie ndụ zuru oke nke Bootstrap ma hazie ya ka ọ bụrụ mkpa gị, jiri faịlụ isi mmalite dịka akụkụ nke usoro nchịkọta ọrụ gị.

Nke mbụ, mepụta nke gị _custom.scsswee jiri ya kagbuo ụdị mgbanwe omenala arụnyere n'ime ya . Mgbe ahụ, jiri isi faịlụ Sass gị bubata mgbanwe omenala gị, Bootstrap sochiri ya:

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

Maka Bootstrap iji chịkọta, jide n'aka na ị wụnye ma jiri ihe ndị a chọrọ: sass-loader , postcss-loader with Autoprefixer . Site na nhazi ntakịrị, nhazi akpa weebụ gị kwesịrị ịgụnye iwu a ma ọ bụ ihe yiri ya:

// ...
{
  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'
  }]
}
// ...

Na-ebubata CSS chịkọtara

N'aka nke ọzọ, ịnwere ike iji CSS dị njikere iji Bootstrap site na ịgbakwunye ahịrị a na ntinye ọrụ gị:

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

N'okwu a, ịnwere ike iji iwu gị dị ugbu a na- cssenweghị mgbanwe ọ bụla na nhazi webpack, belụsọ na ịchọghị sass-loadernaanị ụdị-loader na css-loader .

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