根据 Bootstrap 5 官方文档,我们可以从bootstrap/js/dist
(Webpack, rollup, ...) 中导入预编译的 js 文件并构建自定义包。
https://getbootstrap.com/docs/5.0/getting-started/javascript/#individual-or-compiled
在 docs 的优化部分,他们给出了如何导入 js 文件的示例。 https://getbootstrap.com/docs/5.0/customize/optimize/#lean-javascript
问题:
我创建了一个名为bootstrap.js
import 'bootstrap/js/dist/tooltip';
Run Code Online (Sandbox Code Playgroud)
我只想使用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' …
Run Code Online (Sandbox Code Playgroud)