Source

Webpack

A'oa'o pe fa'afefea ona fa'aofi Bootstrap i lau poloketi e fa'aaoga ai le Webpack 3.

Fa'apipi'i le Bootstrap

Faʻapipiʻi le bootstrap o se Node.js module e faʻaaoga ai le npm.

Fa'aulufaleina o le Javascript

Fa'aulufale mai le Bootstrap's JavaScript e ala i le fa'aopoopoina o le laina lea i le mea e ulufale ai lau app (masani index.jspe app.js):

import 'bootstrap';

I le isi itu, e mafai ona e faʻaulufaleina mai plugini taʻitasi pe a manaʻomia:

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

O le Bootstrap e faʻalagolago i le jQuery ma Popper , o loʻo faʻamatalaina o le peerDependencies, o lona uiga e tatau ona e faʻamautinoa e faʻaopoopo uma i latou i lou package.jsonfaʻaaogaina npm install --save jquery popper.js.

Matau pe afai e te filifili e faaulufale mai plugins taitoatasi , e tatau foi ona e faapipii exports-loader

Fa'aulufaleina Sitaili

Fa'aulufaleina mai o Sass Precompiled

Ina ia fiafia i le gafatia atoatoa o Bootstrap ma faʻavasegaina i ou manaʻoga, faʻaoga faila faila o se vaega o le faʻagasologa o le faʻapipiʻiina o lau poloketi.

Muamua, fai sau oe lava _custom.scssma fa'aoga e fa'amalo ai suiga fa'ale-aganu'u ua fausia . Ona, faʻaoga lau faila sass autu e faʻaulu mai ai au suiga masani, sosoo ai ma Bootstrap:

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

Mo Bootstrap e faʻapipiʻi, ia mautinoa e te faʻapipiʻi ma faʻaogaina mea e manaʻomia: sass-loader , postcss-loader with Autoprefixer . Faatasi ai ma se seti laʻititi, o lau upega tafaʻilagi config e tatau ona aofia ai lenei tulafono pe tutusa:

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

Fa'aulufaleina CSS Compiled

I le isi itu, e mafai ona e faʻaogaina le Bootstrap's ready-to-use css e ala i le faʻaopoopoina o lenei laina i le mea e ulufale ai lau poloketi:

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

I lenei tulaga e mafai ona e faʻaogaina lau tulafono o loʻo iai e cssaunoa ma ni suiga faʻapitoa ile webpack config vagana ai e te le manaʻomia sass-loadernaʻo le style-loader ma css-loader .

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