in English

Webpack

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

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

Bootstrap faʻalagolago i le jQuery ma Popper , o loʻo faʻamaonia i totonu o le peerDependenciesmeatotino; o lona uiga e tatau ona e mautinoa e faʻaopoopo uma i latou i lau package.jsonfaʻaoga npm install --save jquery popper.js.

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 postcss actions
    options: {
      plugins: function () { // postcss plugins, can be exported to postcss.config.js
        return [
          require('autoprefixer')
        ];
      }
    }
  }, {
    loader: 'sass-loader' // compiles Sass to CSS
  }]
},
...

Fa'aulufaleina CSS Compiled

I le isi itu, e mafai ona e faʻaogaina le CSS saunia-e-faʻaaoga a Bootstrap i le na o 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']
    }
  ]
}
...