有什么方法可以访问变量 e.q.来自 vendor 文件的 Lobibox
:
./node_modules/lobibox/js/notifications.js
在我自己的配置文件中:./assets/js/lobibox/config.js
?
只是为了覆盖 Lobibox 默认设置。
这是我的堆栈:
./assets/js/lobibox/config.js:
$(function ()
{
Lobibox.notify.DEFAULTS = $.extend({}, Lobibox.notify.DEFAULTS,
{
soundPath: '/temp/static/sound/notifications/',
icon: false,
sound: 'sound4',
width: 320,
pauseDelayOnHover: true,
continueDelayOnInactiveTab: false
});
});
./node_modules/lobibox/js/notifications.js:
var Lobibox = Lobibox || {};
(function () {
// code ..
Lobibox.notify = function (type, options) {
// code ..
};
// code ...
}})();
./entryFile.js:
// Notifications
import './../node_modules/lobibox/js/notifications.js';
import './static/js/notification.js'
现在浏览器显示错误
未捕获的 ReferenceError:Lobibox 未定义
最佳答案
要加载遗留代码,您可以使用 script-loader .
安装脚本加载器:
npm install --save-dev script-loader
在您的 webpack 配置文件中模块规则部分的开头添加新条目:
{ test: /lobibox\/js\/notifications/, loader: "script-loader" }
您应该能够在 window.Lobibox
下访问 Lobibox。
关于javascript - 如何从 webpack 4 中的 vendor 文件获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52689952/