如何使用 Rollup 构建自定义引导程序包

2024-04-21

根据Bootstrap 5官方文档,我们可以从以下位置导入预编译的js文件bootstrap/js/dist并使用(Webpack,rollup,...)构建自定义捆绑包。

https://getbootstrap.com/docs/5.0/getting-started/javascript/#individual-or-compiled https://getbootstrap.com/docs/5.0/getting-started/javascript/#individual-or-compiled

在文档的优化部分,他们给出了如何导入 js 文件的示例。https://getbootstrap.com/docs/5.0/customize/optimize/#lean-javascript https://getbootstrap.com/docs/5.0/customize/optimize/#lean-javascript

问题:我创建了一个名为bootstrap.js

import 'bootstrap/js/dist/tooltip';

我只想使用Tooltip插入。 我使用以下配置进行汇总

  const plugins = [
    babel({
      exclude: 'node_modules/**',
      // Include the helpers in each file, at most one copy of each
      babelHelpers: 'bundled',
      presets: [
        [
          '@babel/preset-env',
          {
            loose: true,
            bugfixes: true,
            modules: false
          }
        ]
      ]
    }),
    nodeResolve()
  ]

  const bundle = await rollup.rollup({
    input: './js/vendors/bootstrap.js',
    plugins,
  })

  await bundle.write({
    format: 'umd',
    file: './file.js'
  })

生成后file.js并使用 HTML 页面,控制台中会显示错误file.js:1727 Uncaught ReferenceError: process is not defined

我也无法使用引导语法来初始化Tooltip plugin new bootstrap.Tooltip给出未定义的错误bootstrap.

我可以通过导入这些文件来实现我想要的js/src文件夹并按其使用方式导出它们js/src/index.umd.js但遵循引导程序官方文档如何导入其插件似乎无法正常工作。


不知道如何剖析你的代码 - 你错过了对 Popper 的全部依赖。

但这就是我会做的(提示:我获取了 BS5 源代码并删除了所有不需要的东西。)

假设您在 Bootstrap 5 的一个分支上进行编译:

File: build\rollup.config.mk.js:

'use strict'

const path = require('path')
const { babel } = require('@rollup/plugin-babel')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const replace = require('@rollup/plugin-replace')
const banner = require('./banner.js')

let fileDest = `bootstrap-mk`
const external = ['@popperjs/core']
const plugins = [
  babel({
    // Only transpile our source code
    exclude: 'node_modules/**',
    // Include the helpers in the bundle, at most one copy of each
    babelHelpers: 'bundled'
  })
]
const globals = {
  '@popperjs/core': 'Popper'
}

const rollupConfig = {
  input: path.resolve(__dirname, `../js/index.mk.umd.js`),
  output: {
    banner,
    file: path.resolve(__dirname, `../dist/js/${fileDest}.js`),
    format: 'umd',
    globals
  },
  external,
  plugins
}

rollupConfig.output.name = 'bootstrap'

module.exports = rollupConfig

... 并且 ...

File: js\index.mk.umd.js

import Tooltip from './src/tooltip'

export default {
  Tooltip
}

然后调用:rollup --config build/rollup.config.mk.js --sourcemap从命令行,或者将类似的内容添加到packacge.json \ "scripts“ 部分:

  "js-compile-mk": "rollup --config build/rollup.config.mk.js --sourcemap",

...然后打电话npm run js-compile-mk从命令行。

输出将是一个名为:dist\js\bootstrap-mk.js (和地图文件)


如果你不想使用叉子,而是使用叉子node_modules子文件夹,然后继续更改路径build\rollup.config.mk.js file.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Rollup 构建自定义引导程序包 的相关文章

随机推荐

  • URL 重写破坏了 CSS 链接

    我使用以下设置进行网址重写 RewriteEngine On RewriteCond REQUEST FILENAME d RewriteCond REQUEST FILENAME f RewriteRule index php url 1
  • October CMS:如何扩展后端用户的角色范围

    我已经能够延长Backend Models User类并添加一个范围查询方法以仅检索超级用户 public function boot User extend function model model gt addDynamicMethod
  • 如何自动链接本地npm包?

    我正在构建两个相互依赖的私有 npm 包 说我有 project my commons package json name my commons version 0 0 1 my server package json dependenci
  • Beaglebone Black 上的 GPIO

    我目前遇到了 Beaglebone black GPIO 引脚的问题 我正在寻找一种正确的方法来读取 C 中的 GPIO 引脚 p8 4 的值 如果我理解正确的话 我尝试使用一个库 该库使用了在引入设备树之前不支持的旧方法 我尝试寻找其他解
  • 如果方法只需要 ajax 调用,会返回什么错误?

    如果操作期望仅通过 AJAX 使用 但在没有正确的 ajax 标头的情况下调用 则操作应返回什么 HTTP 状态 我觉得我应该指出一些错误 但我真的找不到合适的错误 我想最好是 405 Method not allowed 但是如果例如 a
  • PowerShell 中的“net use”不指定驱动器

    通过 net use 您可以执行以下操作 net use server user domian username 然后 它会提示输入密码 并且使用任何程序 cmd Explorer Word 等 与该服务器建立的任何进一步 CIFS 连接都
  • 验证 TextBox 中的文本更改

    我已经在 WinForm 中的文本框上实现了验证规则 并且效果很好 但是 只有当我跳出该字段时 它才会检查验证 我希望它在框中输入任何内容以及每次内容发生变化时立即进行检查 我还希望它在 WinForm 打开后立即检查验证 我记得最近通过设
  • 一页上有多个夏季笔记 div

    我正在尝试获取特定夏季笔记 div 的代码 其中单个页面上有多个笔记 div 我的暑假笔记是用 php 从数据库创建的 如下所示 div class tab content div class tab pane div class summ
  • 如何在大窗口上优化窗口聚合?

    我在 Spark 2 4 4 中使用带有大窗口的窗口函数 例如 Window partitionBy id orderBy timestamp 在我的测试中 我有大约 70 个不同的 ID 但我可能有大约 200 000 行 ID 如果没有
  • 检索 AR 模型的所有关联属性?

    您认为检索 AR 模型所有关联的所有属性的最佳方法是什么 即 假设我们有模型Target class Target lt ActiveRecord Base has many countries has many cities has ma
  • 使用推断的 (?) 类型克隆 std::iter::Map

    我在以紧凑的方式克隆地图时遇到问题 extern crate itertools num use itertools num linspace fn main 440Hz as wave frequency middle A let fre
  • 没有 GameKit 的 iOS 蓝牙

    我已经知道使用 GameKit 我只能连接到运行相同应用程序的其他 iOS 设备 但我想连接到 Parallaz EasyBluetooth 芯片来发送和接收命令 因此我需要不同的解决方案 我想有一些针对越狱设备的库 但我不知道 你能给我一
  • 我什么时候知道 GeoFire 已完成加载,因为它是基于事件的触发器

    因此 我使用 GeoFire 和 AngularFire 来填充我的 ng repeat 项目列表 有一个离子拉动来刷新列表 因此 用户拉动它并获取当前更新的位置并刷新列表 调用 GeoFire 来重新填充列表 scope doRefres
  • 未捕获的类型错误:无法读取未定义的属性(读取“isBatchingLegacy”)

    我正在尝试使用 jest 测试反应打字稿项目 但它给出了一个令人困惑的错误 错误图像 https i stack imgur com gdWQp png 这是我的 package json dependencies testing libr
  • 未捕获的引用错误:谷歌未定义

    我正在尝试将 geoJSON 文件中的标记加载到我的地图上 地图加载正常 但不断出现错误 Uncaught ReferenceError google is not defined 在这一行 google maps event addDom
  • 使用Python修改INI文件

    我有一个 INI 文件需要使用 Python 进行修改 我正在调查ConfigParser模块 但仍然遇到问题 我的代码是这样的 config ConfigParser RawConfigParser config read C itb i
  • 解析,如何向目标用户发送推送通知

    我已成功设置解析推送通知 并且在我的安装表中我同时拥有安装和设备令牌 我真正想做的是将推送通知发送给某些用户 而不是某些设备 如何将安装表绑定到使用表 以便我可以由用户进行查询并返回要推送到的设备ID From https parse co
  • 如何将 Maxmind .MMDB 转换为 .DAT?

    如何将 MaxMinds MMDB GeoIP 转换为 DAT 格式 以便我可以与 modsecurity Apache 一起使用 Modsecurity 仅支持 DAT 格式 截至 2019 年 2 月 以下 Python 脚本是将 Ge
  • 任务之间的气流延迟

    As you can see in the image airflow is making too much time between tasks execution it almost represents 30 of the DAG e
  • 如何使用 Rollup 构建自定义引导程序包

    根据Bootstrap 5官方文档 我们可以从以下位置导入预编译的js文件bootstrap js dist并使用 Webpack rollup 构建自定义捆绑包 https getbootstrap com docs 5 0 gettin