Laravel NPM 包 |无法访问包
Laravel NPM Package | Cannot Access the Package
长话短说。我已经通过 NPM 安装了一个包到 Laravel 应用程序中。我有运行npm run dev
,构建成功;我在开发应用程序时也 运行 npm run watch
。
我也将这一行放在 app.js
文件中:
import Push from 'push.js';
我已经包括了:
<script src="{{ asset('js/app.js') }}" defer></script>
行到我的主模板文件中。
但是我仍然收到此错误:
Push is not defined
尝试使用包时。
(Laravel 5.8)
如果您尝试在 app.js
(及其通过 import
或 require
的子项) 之外使用它,例如在 Blade 模板中,您可能需要在 app.js
中执行 window.Push = Push
以使其在全球可用。您可以在 Laravel 的默认安装 in the resources/js/bootstrap.js
中看到它。例如:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
长话短说。我已经通过 NPM 安装了一个包到 Laravel 应用程序中。我有运行npm run dev
,构建成功;我在开发应用程序时也 运行 npm run watch
。
我也将这一行放在 app.js
文件中:
import Push from 'push.js';
我已经包括了:
<script src="{{ asset('js/app.js') }}" defer></script>
行到我的主模板文件中。
但是我仍然收到此错误:
Push is not defined
尝试使用包时。
(Laravel 5.8)
如果您尝试在 app.js
(及其通过 import
或 require
的子项) 之外使用它,例如在 Blade 模板中,您可能需要在 app.js
中执行 window.Push = Push
以使其在全球可用。您可以在 Laravel 的默认安装 in the resources/js/bootstrap.js
中看到它。例如:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');