Fa'ase'e ile anotusi autu Fa'ase'e ile su'ega fa'amatalaga
in English

Webpack ma fusi

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

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';

// or get all of the named exports for further usage
import * as bootstrap from 'bootstrap';

I le isi itu, afai e te manaʻomia naʻo ni nai a matou plugins, e mafai ona e faʻaulufaleina taʻitasi plugins pe a manaʻomia:

import Alert from 'bootstrap/js/dist/alert';

// or, specify which plugins you need:
import { Tooltip, Toast, Popover } from 'bootstrap';

Bootstrap faʻalagolago i Popper , lea o loʻo faʻamaonia i totonu o le peerDependenciesmeatotino. O lona uiga e tatau ona e mautinoa e faʻaopoopo i lau package.jsonfaʻaoga npm install @popperjs/core.

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ʻaaoga 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: [{
    // inject CSS to page
    loader: 'style-loader'
  }, {
    // translates CSS into CommonJS modules
    loader: 'css-loader'
  }, {
    // Run postcss actions
    loader: 'postcss-loader',
    options: {
      // `postcssOptions` is needed for postcss 8.x;
      // if you use postcss 7.x skip the key
      postcssOptions: {
        // postcss plugins, can be exported to postcss.config.js
        plugins: function () {
          return [
            require('autoprefixer')
          ];
        }
      }
    }
  }, {
    // compiles Sass to CSS
    loader: 'sass-loader'
  }]
}
// ...

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 i ai mo le cssaunoa ma ni suiga faʻapitoa i le 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'
      ]
    }
  ]
}
// ...