Peera
Akohia me pehea te whakauru i a Bootstrap ki to kaupapa ma te whakamahi i te Parcel.
Tāuta Pūkete
Tāutahia te Parcel Bundler .
Tāutahia te Bootstrap
Tāutahia te bootstrap hei kōwae Node.js mā te npm.
Kei te whakawhirinaki a Bootstrap ki a Popper , kua tohua ki roto i te peerDependencies
rawa. Ko te tikanga me tino mohio koe ki te taapiri i enei mea e rua ki to package.json
whakamahi npm install @popperjs/core
.
Ka oti katoa, ka hangai to kaupapa penei:
project-name/
├── build/
├── node_modules/
│ └── bootstrap/
│ └── popper.js/
├── scss/
│ └── custom.scss
├── src/
│ └── index.html
│ └── index.js
└── package.json
Kawemai JavaScript
Kawemai i te JavaScript a Bootstrap ki te waahi urunga o to taupānga (te tikanga src/index.js
). Ka taea e koe te kawemai i a matou monomai katoa ki roto i te konae kotahi, wehe ke ranei mena ka hiahia koe ki tetahi waahanga iti noa iho.
// 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';
Kawemai CSS
Hei whakamahi i te kaha katoa o Bootstrap me te whakarite kia rite ki o hiahia, whakamahia nga konae puna hei waahanga o te tukanga whakauru o to kaupapa.
Waihanga i a koe ake scss/custom.scss
hei kawemai i nga konae Sass a Bootstrap katahi ka whakakore i nga taurangi ritenga kua hangaia .
Hanga taupānga
Whakauruhia src/index.js
i mua i te tohu kati </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>
Whakatikatikapackage.json
Tāpiri dev
me ngā build
hōtuhi ki tō package.json
kōnae.
"scripts": {
"dev": "parcel ./src/index.html",
"prebuild": "npx rimraf build",
"build": "parcel build --public-url ./ ./src/index.html --experimental-scope-hoisting --out-dir build"
}
Whakahaerehia te tuhinga dev
Ka uru atu to taupānga ki http://127.0.0.1:1234
.
npm run dev
Hanga kōnae taupānga
Ko nga konae i hangaia kei roto i te build/
kōpaki.
npm run build