Source

Paetukutuku

Akohia me pehea te whakauru i a Bootstrap ki to kaupapa ma te whakamahi i te Tukutuku 3.

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

import 'bootstrap';

Hei tauira, ka taea e koe te kawemai i nga taputapu takitahi ina hiahiatia:

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

Kei te whakawhirinaki a Bootstrap ki te jQuery me te Popper , kua tautuhia enei, ko te peerDependenciestikanga me mohio koe ki te taapiri i enei mea e rua ki to package.jsonwhakamahi npm install --save jquery popper.js.

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, he rite ranei:

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

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