Bootstrap的Javascript需要jQuery错误

时间:2017-06-01 19:18:32

标签: laravel-5 webpack laravel-mix

我正在尝试设置我的项目,以便它可以提取引导程序。通过npm jquery。 但是,在尝试这样做时,我收到错误:

all.a3297c6….js:5607 Uncaught Error: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript.
    at Object../node_modules/bootstrap/dist/js/bootstrap.min.js

我的webpack.mix.js文件:

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */
 mix.js([
        '././node_modules/jquery/dist/jquery.min.js',
        '././node_modules/bootstrap/dist/js/bootstrap.min.js', 
        'resources/assets/js/app.js',
    ],'public/js/all.js').version();

 mix.styles([
        '././node_modules/bootstrap/dist/css/bootstrap.min.css',
        'resources/assets/css/theme/common.css', 
        'resources/assets/css/theme/animate+animo.css',
        'resources/assets/css/theme/csspinner.css',
        'resources/assets/css/theme/landing.css',
        '././node_modules/sweetalert/dist/sweetalert.css',
        'resources/assets/css/loader.css',
        '././node_modules/nouislider/distribute/nouislider.css',
        'resources/assets/css/theme/app.css',
    ], 'public/css/all.css').version();

我的app.js文件:

import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from 'axios'
window.jQuery = window.$ = require('jquery');
import 'bootstrap'

window.Vue = Vue;
Vue.prototype.$http = axios;
Vue.use(VueRouter);

axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content')

//Helper file that contains loading screen logic
require('./helpers');

有趣的是,如果我在刀片文件中使用CDN来获取所有这些,它可以解决问题,但我得到Tether的相同错误(理所当然,它是Bootstrap 4.0的依赖项)。将Tether添加到webpack文件并不能解决这个问题 - 似乎我必须通过CDN添加所有内容(不理想)。

你是不是允许在一个mix.js中捆绑bootstrap,jquery和tether?我怎么能这样做 - 我应该简单地分开bootstrap和jQuery吗?

0 个答案:

没有答案