Holo i ka ʻike nui Holo i ka hoʻokele docs
in English

Webpack a me nā puʻupuʻu

E aʻo pehea e hoʻokomo ai iā Bootstrap i kāu papahana me ka hoʻohana ʻana i ka Webpack a i ʻole nā ​​pūʻulu ʻē aʻe.

Ke kau nei i ka Bootstrap

E hoʻouka i ka bootstrap ma ke ʻano he module Node.js me ka npm.

Ke lawe mai nei i ka JavaScript

E hoʻokomo i ka JavaScript a Bootstrap ma ka hoʻohui ʻana i kēia laina i ka wahi komo o kāu polokalamu (maʻamau a i index.jsʻole app.js):

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

ʻO kahi ʻē aʻe, inā makemake ʻoe i kahi liʻiliʻi wale nō o kā mākou plugins, hiki iā ʻoe ke hoʻokomo i nā plugins pākahi e like me ka mea e pono ai:

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

Ke hilinaʻi nei ʻo Bootstrap iā Popper , i kuhikuhi ʻia i ka peerDependencieswaiwai. ʻO ke ʻano kēia e pono ʻoe e hōʻoia e hoʻohui iā ia i kāu package.jsonhoʻohana ʻana npm install @popperjs/core.

Kaila lawe mai

Ke lawe mai nei i nā Sass i hoʻopili mua ʻia

No ka leʻaleʻa i ka mana piha o Bootstrap a hoʻopilikino iā ia i kāu pono, e hoʻohana i nā faila kumu ma ke ʻano he ʻāpana o ke kaʻina hana pūʻulu o kāu papahana.

ʻO ka mea mua, hana i kāu ponoʻī _custom.scssa hoʻohana iā ia e hoʻopau i nā ʻano maʻamau i kūkulu ʻia . A laila, e hoʻohana i kāu faila Sass nui e hoʻokomo i kāu mau loli maʻamau, a ukali ʻia e Bootstrap:

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

No ka hōʻuluʻulu ʻana o Bootstrap, e hōʻoia ʻoe e hoʻokomo a hoʻohana i nā mea hoʻouka pono: sass-loader , postcss-loader me Autoprefixer . Me ka hoʻonohonoho liʻiliʻi, pono kāu hoʻonohonoho pūnaewele pūnaewele e hoʻokomo i kēia lula a i ʻole like:

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

Ke lawe mai nei i ka CSS i houluuluia

ʻO kahi ʻē aʻe, hiki iā ʻoe ke hoʻohana i ka CSS mākaukau hoʻohana a Bootstrap ma ka hoʻohui ʻana i kēia laina i ka helu komo o kāu papahana:

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

I kēia hihia, hiki iā ʻoe ke hoʻohana i kāu lula e kū nei cssme ka ʻole o nā hoʻololi kūikawā i ka webpack config, koe wale nō ʻaʻole pono ʻoe i sass-loaderka style-loader a me css-loader wale nō .

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