尝试使用 Laravel mix / webpack 时出现 JS 错误
JS errors when trying to use Laravel mix / webpack
我有一个 webpack 混合文件,看起来像这样。
let mix = require('laravel-mix');
let basePath = 'app/Resources/assets/sass/';
let jsPath = 'app/Resources/assets/js/';
mix.setPublicPath('./web');
mix.browserSync({proxy: 'rooms.test', ghost: false});
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
mix.sass(basePath + 'base.scss', 'web/assets_static/css');
mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/slick-carousel/slick/slick.js',
'./node_modules/picturefill/picturefill.js',
'./node_modules/swipebox/src/js/jquery.swipebox.js',
'./node_modules/moment/min/moment.min.js',
'./node_modules/jquery-pjax/jquery.pjax.js',
jsPath + '/info-pane.js',
jsPath + '/base.js'], 'web/assets_static/js/base.js');
加载页面时出现此错误。
base.js:15708 Uncaught TypeError: Cannot read property 'defaults' of
undefined
at HTMLDocument.<anonymous> (base.js:15708)
at mightThrow (base.js:3583)
at process (base.js:3651)
这行是:
$.pjax.defaults.timeout = 25000;
...所以看起来基本 js 文件由于某种原因没有看到 pjax 文件 - 即使它在 webpack.mix.js.
我正在撕掉我遗漏的那一点点头发 - 非常感谢收到的任何帮助。 :-).
改为粘贴此代码。您在 jsPath
和 basePath
中有一个额外的斜杠检查最后两行您正在向它们添加另一个斜杠
let mix = require('laravel-mix');
let basePath = 'app/Resources/assets/sass'; //you have here an additional slash
let jsPath = 'app/Resources/assets/js'; //and here to
mix.setPublicPath('./web');
mix.browserSync({proxy: 'rooms.test', ghost: false});
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
mix.sass(basePath + 'base.scss', 'web/assets_static/css');
mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/slick-carousel/slick/slick.js',
'./node_modules/picturefill/picturefill.js',
'./node_modules/swipebox/src/js/jquery.swipebox.js',
'./node_modules/moment/min/moment.min.js',
'./node_modules/jquery-pjax/jquery.pjax.js',
jsPath + '/info-pane.js',
jsPath + '/base.js'], 'web/assets_static/js/base.js');
我有一个 webpack 混合文件,看起来像这样。
let mix = require('laravel-mix');
let basePath = 'app/Resources/assets/sass/';
let jsPath = 'app/Resources/assets/js/';
mix.setPublicPath('./web');
mix.browserSync({proxy: 'rooms.test', ghost: false});
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
mix.sass(basePath + 'base.scss', 'web/assets_static/css');
mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/slick-carousel/slick/slick.js',
'./node_modules/picturefill/picturefill.js',
'./node_modules/swipebox/src/js/jquery.swipebox.js',
'./node_modules/moment/min/moment.min.js',
'./node_modules/jquery-pjax/jquery.pjax.js',
jsPath + '/info-pane.js',
jsPath + '/base.js'], 'web/assets_static/js/base.js');
加载页面时出现此错误。
base.js:15708 Uncaught TypeError: Cannot read property 'defaults' of
undefined
at HTMLDocument.<anonymous> (base.js:15708)
at mightThrow (base.js:3583)
at process (base.js:3651)
这行是:
$.pjax.defaults.timeout = 25000;
...所以看起来基本 js 文件由于某种原因没有看到 pjax 文件 - 即使它在 webpack.mix.js.
我正在撕掉我遗漏的那一点点头发 - 非常感谢收到的任何帮助。 :-).
改为粘贴此代码。您在 jsPath
和 basePath
中有一个额外的斜杠检查最后两行您正在向它们添加另一个斜杠
let mix = require('laravel-mix');
let basePath = 'app/Resources/assets/sass'; //you have here an additional slash
let jsPath = 'app/Resources/assets/js'; //and here to
mix.setPublicPath('./web');
mix.browserSync({proxy: 'rooms.test', ghost: false});
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
mix.sass(basePath + 'base.scss', 'web/assets_static/css');
mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/slick-carousel/slick/slick.js',
'./node_modules/picturefill/picturefill.js',
'./node_modules/swipebox/src/js/jquery.swipebox.js',
'./node_modules/moment/min/moment.min.js',
'./node_modules/jquery-pjax/jquery.pjax.js',
jsPath + '/info-pane.js',
jsPath + '/base.js'], 'web/assets_static/js/base.js');