2017-03-06 63 views
2

我已經熟悉laravel 5.1 mix(elixir)了,最近我決定測試laravel 5.4混合。在laravel 5.4上添加jQuery混合

我混合我的供應商文件庫。

mix 
.styles([ 
    './node_modules/bootstrap/dist/css/bootstrap.css', 
    './node_modules/font-awesome/css/font-awesome.css' 
], 'public/css/vendor.css') 
.js([ 
    './node_modules/jquery/dist/jquery.js', 
    './node_modules/bootstrap/dist/js/bootstrap.js', 
], 'public/js/vendor.js') 
.disableNotifications() 
.version(); 

幷包括供應商在我的網頁上。

<script src="{{ mix('js/vendor.js') }}" type="text/javascript" charset="utf-8" async defer></script> 

但是,當我想使用jQuery我在下面的圖片上有這個錯誤。之前,在laravel 5.1中,我完全是這樣做的。

enter image description here

我有什麼做的?

回答

5

只是取消註釋這條線在assets/js/bootstrap.js文件:

window.$ = window.jQuery = require('jquery'); 

,並確保所需要的引導文件放在assets/js/app.js像這樣:

require('./bootstrap'); 
+0

謝謝!它現在有效 –

1
mix.autoload({ 'jquery': ['window.$', 'window.jQuery'] }) 

我不得不把它添加到我的webpack.mix.js

+0

我試過這樣做,但沒有爲我工作。 –

+0

對於它的工作,您的資源/資產/ js/bootstrap.js必須是必需的。並且其中必須包含以下行。 'window。$ = window.jQuery = require('jquery');' – pat64j