Phukusi
Phunzirani momwe mungaphatikizire Bootstrap mu polojekiti yanu pogwiritsa ntchito Parcel.
Ikani Parcel
Ikani Parcel Bundler .
Ikani Bootstrap
Ikani bootstrap ngati gawo la Node.js pogwiritsa ntchito npm.
Bootstrap imadalira Popper , yomwe imatchulidwa mu peerDependencies
katunduyo. Izi zikutanthauza kuti muyenera kuwonetsetsa kuti mwawonjezera zonse ziwiri pazomwe mukugwiritsa package.json
ntchito npm install @popperjs/core
.
Zonse zikamalizidwa, polojekiti yanu idzakonzedwa motere:
project-name/
├── build/
├── node_modules/
│ └── bootstrap/
│ └── popper.js/
├── scss/
│ └── custom.scss
├── src/
│ └── index.html
│ └── index.js
└── package.json
Kulowetsa JavaScript
Lowetsani JavaScript ya Bootstrap polowera pulogalamu yanu (nthawi zambiri src/index.js
). Mutha kuitanitsa mapulagini athu onse mufayilo imodzi kapena padera ngati mukufuna kagawo kakang'ono kawo.
// Import all plugins
import * as bootstrap from 'bootstrap';
// Or import only needed plugins
import { Tooltip as Tooltip, Toast as Toast, Popover as Popover } from 'bootstrap';
// Or import just one
import Alert as Alert from '../node_modules/bootstrap/js/dist/alert';
Kuitanitsa CSS
Kuti mugwiritse ntchito mphamvu zonse za Bootstrap ndikuzisintha kuti zigwirizane ndi zosowa zanu, gwiritsani ntchito mafayilo oyambira ngati gawo lantchito yanu yomangirira.
Pangani anu scss/custom.scss
kuti mulowetse mafayilo a Sass a Bootstrap ndikupitilira zosintha zomwe zakhazikitsidwa .
Pangani pulogalamu
Phatikizani chizindikiro src/index.js
chisanatseke </body>
.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src="./index.js"></script>
</body>
</html>
Sinthanipackage.json
Onjezani dev
ndi build
zolemba mu package.json
fayilo yanu.
"scripts": {
"dev": "parcel ./src/index.html",
"prebuild": "npx rimraf build",
"build": "parcel build --public-url ./ ./src/index.html --experimental-scope-hoisting --out-dir build"
}
Yendetsani dev script
Pulogalamu yanu ipezeka pa http://127.0.0.1:1234
.
npm run dev
Pangani mafayilo apulogalamu
Mafayilo omangidwa ali build/
mufoda.
npm run build