Source

Webpack

Ithute ho kenyelletsa Bootstrap morerong oa hau u sebelisa Webpack.

Ho kenya Bootstrap

Kenya bootstrap joalo ka mojule oa Node.js u sebelisa npm.

E kenya JavaScript

Kenya JavaScript ea Bootstrap ka ho kenya mohala ona moo u kenang teng (hangata index.jskapa app.js):

import 'bootstrap';

Ntle le moo, o ka kenya li-plugins ka bonngoe ha ho hlokahala:

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

Bootstrap e itšetlehile ka jQuery le Popper , tsena li hlalosoa e le peerDependencies, sena se bolela hore u tla tlameha ho etsa bonnete ba hore u li kenya ka bobeli package.jsontšebelisong ea hau npm install --save jquery popper.js.

Mekhoa ea ho Romela ka ntle

Ho kenya Sass esale pele

Ho natefeloa ke bokhoni bo felletseng ba Bootstrap le ho e etsa ho latela litlhoko tsa hau, sebelisa lifaele tsa mohloli e le karolo ea ts'ebetso ea ho kopanya morero oa hau.

Ntlha ea pele, iketsetse ea hau ' _custom.scssme u e sebelise ho fetisa mefuta e sa tšoaneng ea tloaelo e hahiloeng . Ebe, sebelisa faele ea hau ea mantlha ea Sass ho kenya mefuta ea hau ea tloaelo, e lateloe ke Bootstrap:

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

Bakeng sa ho bokella Bootstrap, etsa bonnete ba hore u kenya le ho sebelisa lisebelisoa tse hlokahalang: sass-loader , postcss-loader with Autoprefixer . Ka tlhophiso e fokolang, tlhophiso ea pakete ea hau ea marang-rang e lokela ho kenyelletsa molao ona kapa o tšoanang:

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

Ho kenya CSS e Kopantsoeng

Ntle le moo, o ka sebelisa CSS e ikemiselitseng ho sebelisoa ea Bootstrap ka ho kenyelletsa mohala ona sebakeng sa ho kena sa morero:

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

Tabeng ena o ka sebelisa molao oa hau o seng o ntse o le teng cssntle le liphetoho tse khethehileng ho webpack config, ntle le hore ha u hloke sass-loaderfeela style-loader le css-loader .

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