Source

Webpack

Ithute ho kenyelletsa Bootstrap morerong oa hau u sebelisa Webpack 3.

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/dropdown';
...

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.

Hlokomela hore haeba u khetha ho kenya li-plugins ka bonngoe , u tlameha ho kenya li-exports-loader

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.

Taba ea pele, iketsetse ea hau ' _custom.scssme u e sebelise ho hlakola litloaelo tse hahelletsoeng . 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 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
    }]
  },
  ...

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 projeke ea hau:

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

Tabeng ena o ka sebelisa molao oa hau o teng bakeng sa cssntle le liphetoho tse khethehileng ho webpack config ntle le haeba u sa hloke sass-loaderfeela style-loader le css-loader .

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