Source

Nyatakakadzraɖoƒe ƒe agbalẽvi

Srɔ̃ alesi nàde Bootstrap wò dɔa me to Webpack 3 zazã me.

Bootstrap ƒe ɖoɖowɔwɔ

De bootstrap abe Node.js module ene to npm zazã me.

JavaScript ƒe tsɔtsɔ va dukɔa me

Tsɔ Bootstrap ƒe JavaScript la va to fli sia tsɔtsɔ kpe ɖe wò dɔwɔnua ƒe teƒe si nàge ɖo ŋu (zi geɖe la, index.jsalo app.js):

import 'bootstrap';

Alo àte ŋu atsɔ plugins ɖekaɖeka ne ehiã:

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

Bootstrap nɔ te ɖe jQuery kple Popper dzi , woɖe esiawo gɔme be peerDependencies, esia fia be ele be nàkpɔ egbɔ be yetsɔ wo ame evea siaa kpe ɖe wò package.jsonzazã npm install --save jquery popper.jsŋu .

De dzesii be ne ètiae be yeatsɔ plugins ɖekaɖeka la, ele be nàde exports-loader hã ɖe wò kɔmpiuta dzi

Atsyãwo tsɔtsɔ va dukɔa me

Sass si Woƒo Ƒu Do Ŋgɔ la tsɔtsɔ va dukɔa me

Be nàse vivi na Bootstrap ƒe ŋutete bliboa eye nàtrɔ asi le eŋu wòasɔ ɖe wò hiahiãwo nu la, zã dzɔtsoƒe faɛlwo abe wò dɔa ƒe ƒuƒoƒo ƒe ɖoɖoa ƒe akpa aɖe ene.

Gbã la, wɔ tɔwò _custom.scsseye nàzãe atsɔ axe mɔ ɖe custom variables siwo wotu ɖe eme la nu . Emegbe, zã wò sass faɛl vevitɔ nàtsɔ axɔ wò tɔtrɔ siwo nèwɔ ɖe ɖoɖo nu, eye nàtsɔ Bootstrap akplɔe ɖo:

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

Be Bootstrap naƒo ƒu la, kpɔ egbɔ be yede agbatsɔnu siwo hiã la eye yezã wo: sass-loader , postcss-loader kple Autoprefixer . Ne èwɔ ɖoɖo sue aɖe ko la, ele be wò webpack ƒe ɖoɖowɔɖia nade se sia alo esi sɔ kplii me:

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

CSS si Woƒo Ƒu la Ƒe Xɔxɔ

Alo, àteŋu azã Bootstrap ƒe css si sɔ na zazã to fli sia tsɔtsɔ kpe ɖe wò dɔa ƒe gegeɖeƒe ŋu ko me:

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

Le nɔnɔme sia me la, àteŋu azã wò se si li fifia na tɔtrɔ tɔxɛ aɖeke manɔmee na webpack config negbe ɖeko cssmèhiã style-loader kple css-loader ko o.sass-loader

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