Tīpoka ki te ihirangi matua Tīpoka ki te whakaterenga tuhinga
in English

Paetukutuku me nga paihere

Akohia me pehea te whakauru i a Bootstrap ki to kaupapa ma te whakamahi i te Webpack me etahi atu paihere.

Tāuta Bootstrap

Tāutahia te bootstrap hei kōwae Node.js mā te npm.

Kawemai JavaScript

Kawemai i te JavaScript a Bootstrap ma te taapiri i tenei raina ki te waahi urunga o to taupānga (te nuinga o te waa index.jsranei app.js):

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

Hei tauira, mena ka hiahia koe ki etahi o a maatau mono, ka taea e koe te kawemai i nga taputapu takitahi ina hiahiatia:

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

Kei te whakawhirinaki a Bootstrap ki a Popper , kua tohua ki roto i te peerDependenciesrawa. Ko te tikanga me tino mohio koe ki te taapiri atu ki to package.jsonwhakamahi npm install @popperjs/core.

Kawemai Kāhua

Kei te kawemai i a Sass kua whakahiato-mua

Ki te pai ki te katoa o Bootstrap me te whakarite kia rite ki o hiahia, whakamahia nga konae puna hei waahanga o te mahi paihere o to kaupapa.

Tuatahi, hanga i a koe ake _custom.scsska whakamahi ki te whakakore i nga taurangi ritenga kua hangaia . Na, whakamahia to kōnae Sass matua ki te kawemai i o taurangi ritenga, ka whai mai ko Bootstrap:

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

Mo te whakahiato a Bootstrap, me whakauru koe me te whakamahi i nga kaieke e hiahiatia ana: sass-loader , postcss-loader with Autoprefixer . Ma te iti o te tatūnga, me whakauru atu ki to whirihora kete tukutuku tenei ture, penei ranei:

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

Te kawemai i te CSS kua whakaemihia

Hei tauira, ka taea e koe te whakamahi CSS reri-ki-te whakamahi a Bootstrap ma te taapiri noa i tenei raina ki te waahi urunga o to kaupapa:

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

I tenei keehi ka taea e koe te whakamahi i to ture o naianei mo te csskore he whakarereketanga motuhake ki te whirihoranga webpack, engari karekau koe e hiahia sass-loaderki te momo-whakaeke me te css-loader anake .

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