【发布时间】:2021-08-19 15:18:15
【问题描述】:
我已成功使用 Grunt 将 bootstrap 5 scss 捆绑到一个文件中。我已经设置好了,所以我可以根据项目的需要添加和删除组件 scss 以进行优化。
我现在正在尝试对 js 做同样的事情。
我正在使用 grunt-contrib-uglify 完成以下任务:
uglify: {
site: {
options: {
sourcemap: false
},
files: {
'example/static/example/assets/js/example.min.js': [
// popper bs5 dependency
'node_modules/@popperjs/core/dist/umd/popper.js',
// bootstrap 5 core js
'node_modules/bootstrap/js/dist/dom/data.js',
'node_modules/bootstrap/js/dist/dom/event-handler.js',
'node_modules/bootstrap/js/dist/dom/manipulator.js',
'node_modules/bootstrap/js/dist/dom/selector-engine.js',
// component js
// note ordering of components can be important
// eg. popover relies on tooltip, therefore tooltip must therefore go first
'node_modules/bootstrap/js/dist/base-component.js',
'node_modules/bootstrap/js/dist/alert.js',
'node_modules/bootstrap/js/dist/button.js',
'node_modules/bootstrap/js/dist/carousel.js',
'node_modules/bootstrap/js/dist/collapse.js',
'node_modules/bootstrap/js/dist/dropdown.js',
'node_modules/bootstrap/js/dist/modal.js',
'node_modules/bootstrap/js/dist/offcanvas.js',
'node_modules/bootstrap/js/dist/scrollspy.js',
'node_modules/bootstrap/js/dist/tab.js',
'node_modules/bootstrap/js/dist/toast.js',
'node_modules/bootstrap/js/dist/tooltip.js',
'node_modules/bootstrap/js/dist/popover.js',
// custom js
'example/src/js/**/*.js'
]
}
},
},
我将它包含在我的 html 中,然后在它下面有一个脚本,例如。
<script>
var myOffcanvas = document.getElementById('offcanvasExample')
var bsOffcanvas = new bootstrap.Offcanvas(myOffcanvas)
</script>
我得到错误:
ReferenceError:未定义引导程序
在控制台中。我从捆绑包中缺少什么来完成这项工作?我在 Github 上使用了 npm bs5 starter 作为文件的参考,例如。 popper 依赖,核心 js 并在 node_modules/bootstrap/js/dist 文件夹中导入所有其他组件文件。
Github Bootstrap 5 npm starter
引导 5.1
波普尔 2.9.2
编辑:与分布式捆绑包一起正常工作。
【问题讨论】:
标签: javascript gruntjs bootstrap-5