【发布时间】:2019-03-12 14:17:18
【问题描述】:
我第一次使用 Yarn。我已经安装了最新版本的 Laravel Boilerplate (http://laravel-boilerplate.com/) 并且使用了 Yarn。
我需要包含 JS 库 DataTables (https://datatables.net/)。 不幸的是,我是 Yarn 的新手,我不确定我是否做对了一切,因为我得到了错误:
[显示/隐藏消息详细信息。] ReferenceError: $ is not defined
在这一行:
$(document).ready(function() {
...
这告诉我它找不到 jquery 库,但它应该在那里。
这里是 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.setPublicPath('public');
mix.sass('resources/sass/frontend/app.scss', 'css/frontend/frontend.css')
.sass('resources/sass/backend/app.scss', 'css/backend/backend.css')
.js('resources/js/frontend/app.js', 'js/frontend/frontend.js')
.js([
'resources/js/backend/before.js',
'resources/js/backend/app.js',
'resources/js/backend/after.js'
], 'js/backend/backend.js')
.extract([
'jquery',
'datatables.net-dt',
'bootstrap',
'popper.js/dist/umd/popper',
'axios',
'sweetalert2',
'lodash',
'@fortawesome/fontawesome-svg-core',
'@fortawesome/free-brands-svg-icons',
'@fortawesome/free-regular-svg-icons',
'@fortawesome/free-solid-svg-icons'
]);
if (mix.inProduction() || process.env.npm_lifecycle_event !== 'hot') {
mix.version();
}
每次我调用命令“yarn prod”以创建 CSS 和 js 文件,但 DataTables 不工作。
我错过了什么吗?
提前致谢!
【问题讨论】:
标签: javascript datatables yarnpkg