【发布时间】:2017-05-10 13:30:09
【问题描述】:
我花了两天时间尝试使用 Webpack 捆绑 Bootstrap。我已经让 jQuery 工作了,但为了让 Bootstrap 能够完全运行,我们还需要 Tether 工作(在我的情况下 - 用于弹出框)。我关注了this guide 和this package。尽管如此,问题仍然存在,我收到错误消息,告诉我 popover 不是函数。
我的配置是这样的。
var webpack = require("webpack");
module.exports = {
entry: ["babel-polyfill", "./index.js"],
//entry: ["babel-polyfill", "./index.js", "tether"],
output: { path: __dirname, filename: "bundle.js" },
plugins: [new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
jquery: "jquery",
"window.$": "jquery",
"window.jQuery": "jquery",
"window.jquery": "jquery",
"Tether": "tether",
"window.Tether": "tether",
// Popover: "exports?Popover!bootstrap/js/dist/popover",
})],
...
}
在过去的几天里,我几乎尝试了任何东西,但我的弹药已经用完了。如何进一步排除故障?
还有一些similar issues 未解决,但也有一些似乎get Tether unwillingly。此刻的我好迷茫,想哭……
【问题讨论】:
-
我不需要这个配置,你可以看我的例子here 和 webpack。我刚刚在index.html 中导入了它,它起作用了。
-
@saurabh 我在 package.json 中看不到有关 Tether(或 Bootstrap,在我的情况下是需要 Tether 的)的任何信息。我们在谈论同一个 popover() 吗?
-
@saurabh 啊,对不起。是我不够清楚。当我看到你的消息时,我已经在床上了。是的,正如您所说,从 index.html 到源的链接有效 - 这就是我目前解决它的方式。我现在要解决的问题是我想将它们全部打包(jquery.js、tether.js 和 bootstrap.js)到单个 bundle.js 文件中。我也打算为所有的 CSS 这样做,但我认为 Webpack 可能并不像每个人都在唱的那么好,呵呵。
-
如果您有时间尝试一下 Webpack 的 捆绑 方法,请随意拍摄。我团队的一个伙伴提到,如果这个问题得到妥善和彻底的解决,他将奖励 +100。
标签: jquery twitter-bootstrap webpack bootstrap-4 vue.js