【发布时间】:2018-09-23 23:13:34
【问题描述】:
在为看似非常常见的问题寻找解决方案数小时后,对此做噩梦,目前只是在兜圈子。
我最近将我的 Laravel 项目从使用 gulp 更改为 Laravel Mix、SASS 等,但我的 JS 无法正常运行。
在刀片/php 模板中使用 jQuery * inline * 的任何操作都失败:
Uncaught ReferenceError: jQuery is not defined
webpack.mix.js(带有一系列模块):
let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js').extract(
['jquery', 'foundation-sites', 'vue', 'toastr', 'jscroll', 'chosen-js', 'what-input']
);
mix.sass('resources/assets/sass/app.scss', 'public/css');
master.blade.php(extract method 将它们分开):
<script type="text/javascript" src="/js/manifest.js"></script>
<script type="text/javascript" src="/js/vendor.js"></script>
<script type="text/javascript" src="/js/app.js"></script>
app.js:
const jQuery = require('jquery');
// window.$ = global.jQuery = $;
// window.jQuery = jQuery;
const toastr = require('toastr');
const chosen = require('chosen-js');
const whatInput = require('what-input');
const Foundation = require('foundation-sites');
const Vue = require('Vue');
const jScroll = require('jscroll');
const mousetrap = require('mousetrap');
我尝试过导入,直接要求,离开要求并使用自动加载方法,似乎没有任何效果。一些变体会说 $ 也没有定义,只是不知道该去哪里。
有人可以指导我正确的方向吗?多年来一直使用 Laravel 和 gulp,但只使用 vanilla JS,这个 webpack 让我很难过。
【问题讨论】:
标签: javascript php laravel webpack laravel-mix