Categories: bootstrap5 教程

Bootstrap5 Parcel

了解如何在你的Bootstrap项目中使用 Parcel。

安装Parcel

安装Parcel bundler

安装Bootstrap

使用 npm 将Bootstrap安装为 Node.js 模块。

Bootstrap 依赖于 Popper,它在​peerDependencies​属性中指定。这意味着您必须确保使用​npm install@popperjs/core​将它们添加到​package.json​中。

全部完成后,您的项目的结构将如下所示:

project-name/
├── build/
├── node_modules/
│   └── bootstrap/
│   └── popper.js/
├── scss/
│   └── custom.scss
├── src/
│   └── index.html
│   └── index.js
└── package.json

导入 JavaScript

在应用程序的入口点导入 Bootstrap JavaScript(通常是​src/index.js​)。您可以在一个文件中导入我们的所有插件,如果您只需要其中的一个子集,也可以单独导入。

// 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;

导入 CSS

要充分利用 Bootstrap 的潜力并根据您的需要对其进行自定义,请将源文件用作项目捆绑过程的一部分。

创建自己​scss/custom.scss​的导入 Bootstrap 的 Sass 文件,然后覆盖内置的自定义变量

构建app

在结束标记​</body>​之前包含​src/index.js

<!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>

编辑 package.json

在您的​package.json​文件中添加​dev​和​build​脚本。

"scripts": {
  "dev": "parcel ./src/index.html",
  "prebuild": "npx rimraf build",
  "build": "parcel build --public-url ./ ./src/index.html --experimental-scope-hoisting --out-dir build"
}

运行dev脚本

您的应用程序将运行在​http://127.0.0.1:1234​。

npm run dev

构建应用程序文件

构建的文件在​build/​文件夹中。

npm run build

admin

这个人很懒,什么都没有留下~

Share
Published by
admin

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

1 月 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

1 月 ago