Parcel
Sinau carane nyakup Bootstrap ing proyek sampeyan nggunakake Parcel.
Pasang Parcel
Pasang Paket Paket .
Instal Bootstrap
Instal bootstrap minangka modul Node.js nggunakake npm.
Bootstrap gumantung ing Popper , sing ditemtokake ing peerDependencies
properti kasebut. Iki tegese sampeyan kudu nggawe manawa nambahake loro-lorone menyang package.json
panggunaan sampeyan npm install @popperjs/core
.
Nalika kabeh wis rampung, proyek sampeyan bakal disusun kaya iki:
project-name/
├── build/
├── node_modules/
│ └── bootstrap/
│ └── popper.js/
├── scss/
│ └── custom.scss
├── src/
│ └── index.html
│ └── index.js
└── package.json
Ngimpor JavaScript
Impor JavaScript Bootstrap ing titik entri app sampeyan (biasane src/index.js
). Sampeyan bisa ngimpor kabeh plugin ing siji file utawa kanthi kapisah yen sampeyan mung mbutuhake subset.
// 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';
Ngimpor CSS
Kanggo nggunakke potensial lengkap Bootstrap lan ngatur kanggo kabutuhan, gunakake file sumber minangka bagéan saka proses bundling project.
Gawe dhewe scss/custom.scss
kanggo ngimpor file Sass Bootstrap banjur ganti variabel khusus sing wis dibangun .
Mbangun app
Kalebu sadurunge tag src/index.js
penutup .</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>
Suntingpackage.json
Tambah dev
lan build
skrip ing package.json
file sampeyan.
"scripts": {
"dev": "parcel ./src/index.html",
"prebuild": "npx rimraf build",
"build": "parcel build --public-url ./ ./src/index.html --experimental-scope-hoisting --out-dir build"
}
Jalanake skrip dev
Aplikasi sampeyan bakal bisa diakses ing http://127.0.0.1:1234
.
npm run dev
Mbangun file app
File sing dibangun ana ing build/
folder kasebut.
npm run build