Webpack le li-bundlers
Ithute ho kenyelletsa Bootstrap morerong oa hau u sebelisa Webpack kapa li-bundler tse ling.
Ho kenya Bootstrap
Kenya bootstrap joalo ka mojule oa Node.js u sebelisa npm.
E kenya JavaScript
Kenya JavaScript ea Bootstrap ka ho kenya mohala ona moo u kenang teng (hangata index.js
kapa app.js
):
// You can specify which plugins you need
import { Tooltip, Toast, Popover } from 'bootstrap';
Ntle le moo, haeba o hloka feela li-plugins tsa rona tse 'maloa, o ka kenya li-plugins ka bonngoe kamoo ho hlokahalang:
import Alert from 'bootstrap/js/dist/alert';
...
Bootstrap e itšetlehile ka Popper , e boletsoeng peerDependencies
setšeng. Sena se bolela hore o tla tlameha ho etsa bonnete ba hore o e eketsa ts'ebelisong ea package.json
hau npm install @popperjs/core
.
Mekhoa ea ho Romela ka ntle
Ho kenya Sass esale pele
Ho natefeloa ke bokhoni bo felletseng ba Bootstrap le ho e etsa ho latela litlhoko tsa hau, sebelisa lifaele tsa mohloli e le karolo ea ts'ebetso ea ho kopanya morero oa hau.
Ntlha ea pele, iketsetse ea hau ' _custom.scss
me u e sebelise ho fetisa mefuta e sa tšoaneng ea tloaelo e hahiloeng . Ebe, sebelisa faele ea hau ea mantlha ea Sass ho kenya mefuta ea hau ea tloaelo, e lateloe ke Bootstrap:
@import "custom";
@import "~bootstrap/scss/bootstrap";
Bakeng sa ho bokella Bootstrap, etsa bonnete ba hore u kenya le ho sebelisa lisebelisoa tse hlokahalang: sass-loader , postcss-loader with Autoprefixer . Ka tlhophiso e fokolang, tlhophiso ea pakete ea hau ea marang-rang e lokela ho kenyelletsa molao ona kapa o tšoanang:
// ...
{
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'
}]
}
// ...
Ho kenya CSS e Kopantsoeng
Ntle le moo, o ka sebelisa CSS e ikemiselitseng ho sebelisoa ea Bootstrap ka ho kenyelletsa mohala ona sebakeng sa ho kena sa morero:
import 'bootstrap/dist/css/bootstrap.min.css';
Tabeng ena o ka sebelisa molao oa hau o seng o ntse o le teng css
ntle le liphetoho tse khethehileng ho webpack config, ntle le hore ha u hloke sass-loader
feela style-loader le css-loader .
// ...
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
}
// ...