in English

Webpack ya go swana le yona

Ithute ka moo o ka akaretšago Bootstrap mo protšekeng ya gago o diriša Webpack.

Go tsenya Bootstrap

Tsenya bootstrap bjalo ka modula wa Node.js o diriša npm.

Go tsenya JavaScript ka ntle

Tsenya JavaScript ya Bootstrap ka go tlaleletša mola wo ntlheng ya go tsena ya tirišo ya gago (gantši index.jsgoba app.js):

import 'bootstrap';

Ka go fapana le moo, o ka tsenya di-plugin ka botee ge go nyakega:

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

Bootstrap e itšetlehile ka jQuery le Popper , tse boletsoeng ka peerDependenciesthepa; se se ra gore o tla swanelwa ke go kgonthiša gore o di oketša ka bobedi go package.jsontšhomišo ya gago npm install --save jquery popper.js.

Go Tsenya Ditaele ka Ntle

Go tsenya ka ntle Sass yeo e kgobokeditšwego Pele

Go thabela bokgoni bjo bo tletšego bja Bootstrap le go e tlwaetša go ya ka dinyakwa tša gago, diriša difaele tša mothopo bjalo ka karolo ya tshepedišo ya go kgoboketša ya projeke ya gago.

Sa mathomo, hlama ya gago _custom.scssgomme o e šomiše go tloša diphetogo tša tlwaelo tše di agetšwego ka gare . Ka morago ga moo, šomiša faele ya gago ye kgolo ya Sass go tsenya diphetogo tša gago tša tlwaelo, gomme ya latelwa ke Bootstrap:

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

Bakeng sa Bootstrap go kgoboketša, kgonthiša gore o tsenya le go šomiša di-loader tše di nyakegago: sass-loader , postcss-loader ka Autoprefixer . Ka peakanyo ye nnyane, peakanyo ya gago ya webpack e swanetše go akaretša molao wo goba wo o swanago le ona:

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

Go tsenya ka ntle CSS ye e kgobokeditšwego

Ka go fapana le moo, o ka šomiša CSS ya Bootstrap yeo e loketšego go šomišwa ka go no oketša mola wo ntlheng ya go tsena ya projeke ya gago:

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

Tabeng ye o ka šomiša molao wa gago wo o lego gona bakeng sa cssntle le diphetogo tše di kgethegilego go webpack config, ntle le gore ga o hloke sass-loaderfeela style-loader le css-loader .

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