Akpa webụ
Mụta otu esi etinye Bootstrap n'ọrụ gị site na iji Webpack.
Ịwụnye Bootstrap
Wụnye bootstrap dị ka modul Node.js site na iji npm.
Na-ebubata JavaScript
Bubata JavaScript nke Bootstrap site na ịgbakwunye ahịrị a na ntinye ngwa gị (na-emekarị index.js
ma ọ bụ app.js
):
import 'bootstrap';
N'aka nke ọzọ, ịnwere ike ibubata plugins n'otu n'otu dịka achọrọ:
import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/alert';
...
Bootstrap dabere na jQuery na Popper , nke akọwapụtara na ihe peerDependencies
onwunwe; nke a pụtara na ị ga-enwerịrị ike ịgbakwunye ha abụọ na iji package.json
gị npm install --save jquery popper.js
.
Ụdị mbubata
Na-ebubata Sass agbakọtagoro
Iji kporie ndụ zuru oke nke Bootstrap ma hazie ya ka ọ bụrụ mkpa gị, jiri faịlụ isi mmalite dịka akụkụ nke usoro nchịkọta ọrụ gị.
Nke mbụ, mepụta nke gị _custom.scss
wee jiri ya kagbuo ụdị mgbanwe omenala arụnyere n'ime ya . Mgbe ahụ, jiri isi faịlụ Sass gị bubata mgbanwe omenala gị, Bootstrap sochiri ya:
@import "custom";
@import "~bootstrap/scss/bootstrap";
Maka Bootstrap iji chịkọta, jide n'aka na ị wụnye ma jiri ihe ndị a chọrọ: sass-loader , postcss-loader with Autoprefixer . Site na nhazi ntakịrị, nhazi akpa weebụ gị kwesịrị ịgụnye iwu a ma ọ bụ ihe yiri ya:
...
{
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
}]
},
...
Na-ebubata CSS chịkọtara
N'aka nke ọzọ, ịnwere ike iji CSS dị njikere iji Bootstrap site na ịgbakwunye ahịrị a na ntinye ọrụ gị:
import 'bootstrap/dist/css/bootstrap.min.css';
N'okwu a, ịnwere ike iji iwu gị dị ugbu a na- css
enweghị mgbanwe ọ bụla na nhazi webpack, belụsọ na ịchọghị sass-loader
naanị ụdị-loader na css-loader .
...
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
}
...