【发布时间】:2022-11-14 16:36:08
【问题描述】:
我从不使用 Vite,我开始在新的 Rails 应用程序中使用它。
我正在尝试在我的应用程序中使用基于引导程序的管理主题,并且我正在使用 Vite for JS。
我有这条线的入口点
import '../admin/vendor/metronic/components/_init'
在 init.js 文件中,我对主题的 js 组件进行了初始化
var KTComponents = function () {
// Public methods
return {
init: function () {
KTApp.init();
KTDrawer.init();
KTMenu.init();
KTScroll.init();
KTSticky.init();
KTSwapper.init();
KTToggle.init();
KTScrolltop.init();
KTDialer.init();
KTImageInput.init();
KTPasswordMeter.init();
}
}
}();
// On document ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function() {
KTComponents.init();
});
} else {
KTComponents.init();
}
// Init page loader
window.addEventListener("load", function() {
KTApp.initPageLoader();
});
// Declare KTApp for Webpack support
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
window.KTComponents = module.exports = KTComponents;
}
当然我有这个错误:
Uncaught ReferenceError: KTApp is not defined
为了解决这个问题,我尝试添加
import KTApp from './app';
但我现在有这个错误
Uncaught SyntaxError: The requested module '/vite-dev/admin/vendor/metronic/components/app.js' does not provide an export named 'default' (at _init.js?t=1668157592237:6:8)
这是 app.js 文件
“使用严格”;
// Class definition
var KTApp = function () {
...
}
// Declare KTApp for Webpack support
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = KTApp;
}
【问题讨论】:
标签: javascript vite