与Webpack捆绑时无法使Tether工作于Bootstrap 4

时间:2016-12-25 23:20:35

标签: jquery twitter-bootstrap webpack bootstrap-4 vue.js

我花了两天时间尝试使用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的人。我现在很困惑,我可以哭...

2 个答案:

答案 0 :(得分:4)

这是我在vueJS项目中使用的Bootstrap JS和SCSS:

webpack.config.js

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': 'vue-style-loader!css-loader!sass-loader',
            'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      },
      {
        test: /\.scss$/,
        loader: 'style-loader!css-loader!sass-loader'
      }
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery', jQuery: 'jquery',
      Tether: 'tether', tether: 'tether'
    }),
  ],
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
};

main.js

// Globally require jQuery, you cannot access jQuery from Console without this code
window.$ = require('jquery')

import 'bootstrap' // importing bootstrap.js
import "bootstrap/scss/bootstrap.scss"
import "./assets/scss/main.scss"

import Vue from 'vue'
import App from './App.vue'

new Vue({
  el: '#app',
  render: h => h(App)
});

main.scss

$font-family-primary: 'Source Sans Pro', sans-serif; // Customize the bootstrap scss
@import '~bootstrap/scss/bootstrap.scss';

我的git设置https://github.com/syed-haroon/vue-js-2-basic-setup

我还建议您查看此网址,了解更为复杂的工作设置https://github.com/prograhammer/example-vue-project

答案 1 :(得分:1)

使用React,webpack和Bootstrap 4,它一直在问我“bootstrap tooltips需要tether”,即使我已经添加了“Tether”:“tether”到插件。 因此,我必须在条目下添加tether / dist / js / tether.min.js才能使其正常工作。见下文

    module.exports = {
  entry: [
    'script-loader!jquery/dist/jquery.min.js',
    'script-loader!tether/dist/js/tether.min.js',
    'script-loader!bootstrap/dist/js/bootstrap.min.js',
    './app/app.jsx',
  ],
  externals: {
    jQuery: 'jQuery'
  },
  plugins: [
    new webpack.ProvidePlugin({
      '$': 'jQuery',
      'jQuery': 'jQuery',
      'Tether': 'tether'
    }),